stringbuilder不能正常工作 [英] stringbuilder not working correctly

查看:73
本文介绍了stringbuilder不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.cs

 受保护的 无效 CheckBox1_CheckedChanged(对象发​​件人,EventArgs e)
    {
        StringBuilder str =  StringBuilder();
        str.Append(" );
        ScriptManager.RegisterClientScriptBlock( this  this  .GetType(), " ,str.ToString(), true );
    } 



.aspx

 <   asp:CheckBox     ID   ="   ="span>   文本  =" 电话"  runat   服务器"  AutoPostBack   ="  
 
                   span>    oncheckedchanged   ="  CheckBox1_CheckedChanged" > 
<   div     ="   p" 样式   float:left ;" <    样式  =" 浮动:左;"  runat   ="     ="   phnoe" 可见   false" >  <  /div 

span> > < br / >

解决方案

('#phnoe').show();)</script>"); ScriptManager.RegisterClientScriptBlock( this this .GetType(), " ,str.ToString(), true ); }



.aspx

 <   asp:CheckBox     ID   ="   ="span>   文本  =" 电话"  runat   服务器"  AutoPostBack   ="  
 
                   span>    oncheckedchanged   ="  CheckBox1_CheckedChanged" > 
<   div     ="   p" 样式   float:left ;" <    样式  =" 浮动:左;"  runat   ="     ="   phnoe" 可见   false" >  <  /div 

span> > < br / >


如果您只想在勾选/取消选中复选框时在页面上显示一个元素,则只需在客户端上使用一些jQuery就可以了-无需整个表格回发并返回脚本

1)编辑您的复选框控件,确保将AutoPostBack设置为false.

2)将以下脚本添加到页面中

 


(文档).ready(function(){


.cs

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        StringBuilder str = new StringBuilder();
        str.Append("<script language='javascript'>($('#phnoe').show();)</script>");
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "chp", str.ToString(), true);
    }



.aspx

<asp:CheckBox ID="ch_p" Text="phone" runat="server" AutoPostBack="true"

        oncheckedchanged="CheckBox1_CheckedChanged"/>
<div id="p" style="float:left;"><asp:TextBox style="float: left;" runat="server" id="phnoe" Visible="false"></div><br />

解决方案

('#phnoe').show();)</script>"); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "chp", str.ToString(), true); }



.aspx

<asp:CheckBox ID="ch_p" Text="phone" runat="server" AutoPostBack="true"

        oncheckedchanged="CheckBox1_CheckedChanged"/>
<div id="p" style="float:left;"><asp:TextBox style="float: left;" runat="server" id="phnoe" Visible="false"></div><br />


If all you are trying to do is show an element on your page when checkbox is ticked\unticked, then you can just do this on the client with a bit of jQuery - no need to have the whole form post back and return script

1) Edit your checkbox control, make sure AutoPostBack is set to false.

2) Add the following script to your page


(document).ready(function() {


这篇关于stringbuilder不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发语言最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆