• 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   }
  • 相关阅读:
    Linux命令 tr
    Linux命令 xargs
    Python 文件读写 文件和路径
    Python 正则表达式 匹配任意字符
    Python 正则表达式 贪心匹配和非贪心匹配
    Python 正则表达式 匹配次数
    Python 正则表达式 利用括号分组
    Python 正则表达式 search vs match
    【转-整理】 SQL2008 提示评估期已过的解决方法
    Java http接口进阶——自我理解为接口框架形式
  • 原文地址:https://www.cnblogs.com/lgx5/p/13572024.html
Copyright © 2020-2023  润新知