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 }