欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-03-07 21:41:45
protected override void onprerender(eventargs e) 1) 加入脚本 复制代码 代码如下: protected override...
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());