显式 __doPostBack() [英] Explicit __doPostBack()

查看:29
本文介绍了显式 __doPostBack()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Button onclientClick 事件上明确添加了 __doPostBack() .

I have explicitly added __doPostBack() on Button onclientClick event .

<asp:Button ID="Button1" runat="server" Text="Button" 
         OnClientClick="__doPostBack('Button1','')"/> 

当我单击按钮时,Page_Load 会调用两次.但是,如果我在页面加载中添加以下代码,则页面加载仅在单击按钮时调用一次.

When I am clicking the button the Page_Load is calling twice. But if I am adding below code inside page load ,page load is calling only once on button click.

Button1.Attributes.Add("onClientClick", "__doPostBack('Button1','')");

同样,如果我添加 return false,它只会在单击页面加载一次时调用它

Again if i add with return false it is giving me it calling only once page load on click

 <asp:Button ID="Button1" runat="server" Text="Button" 
         OnClientClick="__doPostBack('Button1','');return false;"/>

并返回 true 再次给我两次页面加载,但在属性中添加 return true 或 false.添加代码给出相同的结果,只有一个页面加载调用.

and return true is giving me again twice page load ,but adding return true or false in attribute.add code is giving the same result ,only one page load call.

Button1.Attributes.Add("onClientClick", "__doPostBack('Button1','');return true;");

当我尝试以不同的方式添加 __doPostBack 时,我无法理解到底发生了什么.请帮忙.谢谢

I am not able to understand what is going on exactly when I tried to add __doPostBack in different way. Please help. Thanks

推荐答案

通过放置 OnClientClick,然后 asp.net 使用您的代码和 doPostBack 在客户端大小上呈现 onlick 函数.

By placing the OnClientClick, then the asp.net render the onlick function on client size with both your code and a doPostBack.

所以它被调用了 2 次,因为它是自己调用的,1 次是因为你添加的.

So its called 2 times because one its called by self, and one because you added.

这篇关于显式 __doPostBack()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆