• OnPreRender事件常见用法


    1) 加入脚本

    1  protected override void OnPreRender(EventArgs e)
    2   {
    3      base.OnPreRender(e);
    4      this.Page.RegisterClientScriptBlock("InsertText", this.RenderScript());
    5      this.Page.RegisterOnSubmitStatement("StorePostBody", "StorePostBody();");
    6   }

    2) 设定标题   

     1  protected override void OnPreRender(EventArgs e)
     2   {
     3      if(_mainTitle != null)
     4         _mainTitle.Text = ResourceManager.GetString(Title);
     5 
     6      if(_subTitle != null)
     7         _subTitle.Text = ResourceManager.GetString(SubTitle);
     8 
     9      base.OnPreRender (e);
    10  }

    3) 设定按钮客户端事件

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

    4) 设定控件的状态

     1 protected override void OnPreRender(System.EventArgs e)
     2   {
     3     if(replyButton.Visible == false)
     4       ((Literal)FindControl("Sep1")).Visible = false;    
     5 
     6     if(threadSubButton.Visible == false)
     7       ((Literal)FindControl("Sep3")).Visible = false;
     8 
     9     if(rateButton.Visible == false)
    10       ((Literal)FindControl("Sep2")).Visible = false;
    11 
    12     base.OnPreRender (e);
    13  }

    5) 加入脚本块

     1 protected override void OnPreRender(EventArgs e)
     2   {
     3      base.OnPreRender (e);
     4      StringBuilder sb = new StringBuilder();
     5      sb.Append(" ");
     6      sb.Append("  function ToggleRateMenu() {");
     7      sb.Append("    rateMenu = document.getElementById('RateMenu');");
     8      sb.Append("    rateButton = document.getElementById('RateButton');");
     9      sb.Append("");
    10      sb.Append("    rateMenu.style.left = getposOffset(rateButton, /"left/");");
    11      sb.Append("    rateMenu.style.top = getposOffset(rateButton, /"top/") + rateButton.offsetHeight;");
    12      sb.Append("");
    13      sb.Append("    if (rateMenu.style.visibility == /"hidden/") {");
    14      sb.Append("      rateMenu.style.visibility = /"visible/";");
    15      sb.Append("      rateMenu.style.display = 'block';");
    16      sb.Append("    } else {");
    17      sb.Append("      rateMenu.style.visibility = /"hidden/";");
    18      sb.Append("      rateMenu.style.display = 'none';");
    19      sb.Append("    }");
    20      sb.Append("  }");
    21      sb.Append("  ");
    22      sb.Append("  function getposOffset(what, offsettype){");
    23      sb.Append("  var totaloffset=(offsettype==/"left/")? what.offsetLeft : what.offsetTop;");
    24      sb.Append("  var parentEl=what.offsetParent;");
    25      sb.Append("  while (parentEl!=null){");
    26      sb.Append("    totaloffset=(offsettype==/"left/")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;");
    27      sb.Append("    parentEl=parentEl.offsetParent;");
    28      sb.Append("  }");
    29      sb.Append("  return totaloffset;");
    30      sb.Append("}");
    31      sb.Append(" ");
    32      Page.RegisterClientScriptBlock("RatePost",sb.ToString());
    33   }
  • 相关阅读:
    谷歌被墙,怎样给谷歌浏览器加入迅雷下载插件
    python文件和文件夹訪问File and Directory Access
    svn简单介绍
    javaproject积累——树形结构的操作
    Android多线程研究(1)——线程基础及源代码剖析
    Android4.4 Telephony流程分析——彩信(MMS)发送过程
    hadoop优质链接
    Android开发系列(二十一):Spinner的功能和使用方法以及实现列表选择框
    锤子Smartisan T1手机官方4.4.2系统内核版本号信息
    深入研究Clang(五) Clang Lexer代码阅读笔记之Lexer
  • 原文地址:https://www.cnblogs.com/lgx5/p/13572024.html
Copyright © 2020-2023  润新知