显式 __doPostBack()

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)