Explicit __doPostBack()(显式 __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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:显式 __doPostBack()


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01