在C#HtmlButton的prevent回传 [英] prevent postback of HtmlButton in C#
本文介绍了在C#HtmlButton的prevent回传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在cs文件动态创建HtmlButton。
用它添加到面板
I am creating HtmlButton dynamically in .cs file. Adding it to Panel using
HtmlButton b1 = new HtmlButton();
b1.Attribute.Add("onclick","javascript:validateNclick(this.id);");
pnl.Controls.Add(b1); //pnl is Server-side <Asp:Panel>
现在怎么可能I $它p $ pvent回传? 我写的JavaScript它在IE浏览器(不回发),但在Mozilla Firefox的工作(去服务器端code直接)。
请大家帮帮忙。
Now how could i prevent postback of it? I had written javascript which is working in IE(No postback) but not in Mozilla Firefox (go to server-side code directly). please help out.
推荐答案
返回false至prevent回送:
return false to prevent postback:
b1.Attribute.Add("onclick","javascript:validateNclick(this.id);return false;");
更新:结果
你也可以这样做:
Update:
You can also do this:
b1.Attribute.Add("onclick","javascript:return validateNclick(this.id);");
然后在你的 validateNclick
功能,如果你想有回传,返回真正
,如果没有,返回假
。
Then in your validateNclick
function, if you want to have postback, return true
, if not, return false
.
这篇关于在C#HtmlButton的prevent回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文