DotNet OnPreRender(EventArgs e) 事件常用的方法


protected override void OnPreRender(EventArgs e)
1) 加入脚本

复制代码 代码如下:

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
this.Page.RegisterClientScriptBlock("InsertText", this.RenderScript());
this.Page.RegisterOnSubmitStatement("StorePostBody", "StorePostBody();");
}

2) 设定标题
复制代码 代码如下:

protected override void OnPreRender(EventArgs e)
{
if(_mainTitle != null)
_mainTitle.Text = ResourceManager.GetString(Title);
if(_subTitle != null)
_subTitle.Text = ResourceManager.GetString(SubTitle);
base.OnPreRender (e);
}

3) 设定按钮客户端事件
复制代码 代码如下:

protected override void OnPreRender(EventArgs e)
{
Submit.Attributes.Add("onclick", "return SubmitSendToFriend('" + From.ClientID + "', '" + To.ClientID + "');");
}

4) 设定控件的状态
复制代码 代码如下:

protected override void OnPreRender(System.EventArgs e)
{
if(replyButton.Visible == false)
((Literal)FindControl("Sep1")).Visible = false;
if(threadSubButton.Visible == false)
((Literal)FindControl("Sep3")).Visible = false;
if(rateButton.Visible == false)
((Literal)FindControl("Sep2")).Visible = false;
base.OnPreRender (e);
}

5) 加入脚本块
复制代码 代码如下:

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);
StringBuilder sb = new StringBuilder();
sb.Append(" ");
sb.Append(" function ToggleRateMenu() {");
sb.Append(" rateMenu = document.getElementById('RateMenu');");
sb.Append(" rateButton = document.getElementById('RateButton');");
sb.Append("");
sb.Append(" rateMenu.style.left = getposOffset(rateButton, \"left\");");
sb.Append(" rateMenu.style.top = getposOffset(rateButton, \"top\") + rateButton.offsetHeight;");
sb.Append("");
sb.Append(" if (rateMenu.style.visibility == \"hidden\") {");
sb.Append(" rateMenu.style.visibility = \"visible\";");
sb.Append(" rateMenu.style.display = 'block';");
sb.Append(" } else {");
sb.Append(" rateMenu.style.visibility = \"hidden\";");
sb.Append(" rateMenu.style.display = 'none';");
sb.Append(" }");
sb.Append(" }");
sb.Append(" ");
sb.Append(" function getposOffset(what, offsettype){");
sb.Append(" var totaloffset=(offsettype==\"left\")? what.offsetLeft : what.offsetTop;");
sb.Append(" var parentEl=what.offsetParent;");
sb.Append(" while (parentEl!=null){");
sb.Append(" totaloffset=(offsettype==\"left\")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;");
sb.Append(" parentEl=parentEl.offsetParent;");
sb.Append(" }");
sb.Append(" return totaloffset;");
sb.Append("}");
sb.Append(" ");
Page.RegisterClientScriptBlock("RatePost",sb.ToString());



相关阅读:
jQuery 全选效果实现代码
利用javascript移动div层-javascript 拖动层
javascript源代码集锦
33种Javascript 表格排序控件收集
Js+DVML很酷漂亮实用的右键弹出菜单
javascript Array.remove() 数组删除
PHP 创建标签云函数代码
用好Windows Server 2008中几个命令
Rect,RoundRect(矩形)对象
ADO操作access全过程和CListCtrl的用法
javascript String 的扩展方法集合
如何恢复ORACLE中被DROP的列
javascript document.compatMode兼容性
JS 简单展开关闭切换代码
快速导航

Copyright © 2016 phpStudy | 皖ICP备18014864号-4