的OnClientClick不工作 [英] OnClientClick not working
本文介绍了的OnClientClick不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些问题的OnClientClick。
I am having some problem with OnClientClick.
我添加了一个按钮,进入我的网络表单这样。
I added a button into my webform like this.
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
style="top: 307px; left: 187px; position: absolute; height: 26px; width: 90px"
Text="Submit" OnClientClick="return validate()" />
和我写在&LT一个javascript; HEAD&GT;
后,立即&LT;标题方式&gt;
<script language="javascript" type="text/javascript">
function validate() {
if (document.getElementById("<%=TextBox1%>").value == "") {
alert("textbox1 should not be empty");
}
else if(document.getElementById("<%=TextBox2 %>").value==""){
alert("textbox2 should not be empty");
}
}
</script>
TextBox1中
和 TextBox2中
是两个文本框的Id的。
TextBox1
andTextBox2
are the Id's of two textboxes.
但是,当我点击提交按钮,是的OnClick射击,但的OnClientClick不点火。
But when i click on Submit button, OnClick is firing but OnClientClick is not firing.
请告诉我这个问题?
请帮忙。
推荐答案
在从文本框取ID,你将不得不使用&LT;%= TextBox1.ClientID%GT;
在JavaScript。
When taking the ID from the textboxes, you'll have to use <%=TextBox1.ClientID%>
in your javascript.
和你也应该从验证功能在发生错误时返回false
。
替换为你的JavaScript:
Replace your javascript with:
function validate() {
if(document.getElementById('<%=TextBox1.ClientID%>').value == '') {
alert('Textbox1 should not be empty');
return false;
}
if(document.getElementById('<%=TextBox2.ClientID%>').value == '') {
alert('Textbox2 should not be empty');
return false;
}
}
这篇关于的OnClientClick不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文