UseSubmitBehavior (后章)

来源:互联网 发布:水利预算软件app 编辑:程序博客网 时间:2024/05/16 11:55
后章

以上的内容是对button控件的UseSubmitBehavior属性的了解,其实在之前,还有一个问题也是纠缠不清。就是js中return false;的问题。我们结合到UseSubmitBehavior 看看。会有什么效果。
例3:
<asp:Button ID="Button4" runat="server" Text="Button" onclick="Button4_Click" UseSubmitBehavior="false" OnClientClick="alert('hello');"/>
后台:
protected void Button4_Click(object sender, EventArgs e)
        {
              response.write("ddd");
        }
与例2相比多了OnClientClick="alert('hello');;执行后查询源代码

<input type="button" name="Button4" value="Button" onclick="alert('hello');__doPostBack('Button4','')" id="Button4" />

发现__doPostback()js方法在,前面多了句alert('hello');
首先先弹出了hello,(客户端事件),然后输出了ddd(服务器段事件,只不过由客户端触发的).再看下面的例子,
例4:
<asp:Button ID="Button4" runat="server" Text="Button" onclick="Button4_Click" UseSubmitBehavior="false" OnClientClick="alert('hello');return false;"/>
后台:
protected void Button4_Click(object sender, EventArgs e)
        {
              response.write("ddd");
        }
      与例3相比alert('hello');return false;多了句return false;这也是我们讨论的关键。
执行,查看源代码

 <input type="button" name="Button4" value="Button" onclick="alert('hello');return false;__doPostBack('Button4','')" id="Button4" />
__doPostBack('Button4','')
依然在,前面多了句return false;在看看功能上发现弹出了hello,但是没有输出ddd.这就是我们想要的。

原创粉丝点击