admin管理员组文章数量:1332201
I want to trigger on click of a button this:
<asp:Button runat="server" ID="submit" Text="Submit" OnClientClick="country(this.form);" PostBackUrl="/" />
In javascript I m checking validation of the form.The problem is when I m clicking on the button it is not waiting for the validation but its postback to google...
If I do return country(this.form)
then on button click it waits for validation but don't postback after I fill the form. I want something like that if javascript validation is false..then OnClientClick should be return country(this.form)
if its true then only
country(this.form)
I want to trigger on click of a button this:
<asp:Button runat="server" ID="submit" Text="Submit" OnClientClick="country(this.form);" PostBackUrl="http://www.google./" />
In javascript I m checking validation of the form.The problem is when I m clicking on the button it is not waiting for the validation but its postback to google....
If I do return country(this.form)
then on button click it waits for validation but don't postback after I fill the form. I want something like that if javascript validation is false..then OnClientClick should be return country(this.form)
if its true then only
country(this.form)
Share
Improve this question
asked Mar 9, 2010 at 14:19
user219725user219725
2 Answers
Reset to default 8You can do this:
<asp:Button runat="server" ID="submit" Text="Submit"
OnClientClick="if(!country(this.form)) return false;"
PostBackUrl="http://www.google./" />
Since postbacks use a "onclick" overall, your script is perpending to the ASP.Net script, returning means none of that postback script runs. If you use an if and only return out if needed, it'll work.
It makes more sense when you look at the rendered result, something like this:
<input type="submit" name="submit" value="Submit" id="submit" onclick="if(!country(this.form)) return false; WebForm_DoPostBackWithOptions(.....)" />
Write it with return:
<asp:Button runat="server" ID="submit" Text="Submit" OnClientClick="return country(this.form);" PostBackUrl="http://www.google./" />
And your country function will end with return true or false,
function country(form) {
// Validations goes here
return true;// or return false;
}
本文标签: aspnetproblem with onclientclick and postbackurlStack Overflow
版权声明:本文标题:asp.net - problem with onclientclick and postbackurl - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742241139a2438840.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论