按钮事件未在包含母版页的aspx页面中触发

时间:2014-02-04 06:03:17

标签: c# asp.net

    <asp:Button ID="btncomment"  text="Submit Now" Class="btn1" 
 runat="server" OnClick="btncomment_Click" CausesValidation="False"  />

当我在不使用母版页的情况下运行页面时,按钮事件被触发,但如果我使用带有母版页的页面,则按钮事件不会触发。

main Registration = new main(); 
txtPassword.Text = pwdencrypt.Encrypt(txtPassword.Text, true);
string SQL2 = "insert into registration (fullname,email,phone_no,address,password,username) values ('" + txtfullname.Text + "','" + txtEmailAddress.Text + "','" + txtphone.Text + "','" + txtPAddress.Text + "','" + txtPassword.Text + "','" + txtuname.Text + "')";
Registration.saveData(SQL2);
Response.Write("You have successfully registered");
     } 

1 个答案:

答案 0 :(得分:1)

设置"USeSubmitBehaviour=false" and "CauseValidation=false"

UseSubmitBehavior属性指定Button控件是使用浏览器的内置提交函数还是ASP.NET回发机制。

Button UseSubmitBehavior Property

当设置为FALSE时,ASP.NET会添加一个客户端脚本来发布表单。  这使控件开发人员能够使用GetPostBackEventReference方法返回  Button的客户端回发事件。