我有这个严肃的事情:
我有ASP.NET页面,这个页面内容使用ASP.NET控件更新面板。
我有Java脚本函数来进行验证所以当我点击按钮时我将使用onclientclick来调用java函数进行验证,之后完成后应该从后面的代码调用事件点击按钮功能。
我试过vew方法,但它们对我不起作用。
这里是我的代码示例,在我单击onclientclick上的按钮后,将调用java脚本函数进行验证,如果验证正常,则应调用onclick事件。
.................... java脚本函数 ........................
<script type="text/javascript" >
function add(){
if (tag == trye) {
document.getElementById('<%=btnInfor.ClientID%>').click();
alert("DataAdded")
}
else {
alert("Requiered Field Missing.")
return false;
}
}
</script>
.....................
ASP.NET button
...................
<asp:Button ID="btnInfor" runat="server" Text="Add Information" Style="position: absolute;
top: 1659px; left: 433px;"
onclientclick="JavaScript: return myAdd()" />
....................
code behind in C#
......................
protected void btnInfor_Click(object sender, EventArgs e)
{
\\mycode
}
答案 0 :(得分:0)
你设置它的方式是,当你调用document.getElementById(buttonname).click()时,它会一直调用javascript函数,并且实际上永远不会到达你想要调用的服务器端方法。
首先分配服务器端点击事件处理程序:
<asp:Button ID="btnInfor" runat="server" Text="Add Information" Style="position: absolute;
top: 1659px; left: 433px;" OnClick="btnInfor_Click"
onclientclick="JavaScript: return myAdd()" />
然后在你的javascript函数中,在if分支中返回true:
function add(){
if (tag == trye) {
alert("DataAdded");
return true;
}
else {
alert("Requiered Field Missing.")
return false;
}
}
答案 1 :(得分:0)
我看到有两件事会阻止调用C#代码:
return true;
alert("DataAdded")
OnClick="btnInfor_Click"