__doPostBack函数的含义是什么?什么时候使用它?
我在触发服务器端按钮单击事件时遇到问题,所以我在网上找到了一个解决方案,我应该像
<input type="submit" name="button" id="loginButton" value="Submit"
class="button-orange" alt="Register" title="Register" runat = "server" onclick ="this.disabled=true;__doPostBack('loginButton','')"/>
我那样做,并且它有效,但我想知道发生了什么!
I had problem triggering server side button click events so I found a solution on the net that I should do something like
<input type="submit" name="button" id="loginButton" value="Submit"
class="button-orange" alt="Register" title="Register" runat = "server" onclick ="this.disabled=true;__doPostBack('loginButton','')"/>
I did it, and it worked, but I would like to know what is going on!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看这篇文章:
了解 JavaScript __doPostBack 函数
此方法用于将表单提交(回发)到服务器并允许 ASP.NET 框架调用附加到引发回发的控件的适当事件处理程序。
您通常(在简单的情况下)不直接使用该方法 - 它由您放置在页面上的控件在内部使用。
传递给该函数的参数存储在隐藏字段中,并由服务器端的 ASP.NET 框架获取,以便找到引发回发的控件。
Check this article:
Understanding the JavaScript __doPostBack Function
This method is used to submit (post back) a form to the server and allows ASP.NET framework to call appropriate event handlers attached to the control that raised the post back.
You usually (in simple scenarios) don't use the method directly - it is internally used by the controls you drop on the page.
The parameters passed to this function are stored in a hidden field and picked up by ASP.NET framework on the server-side in order to find the control that raised the post back.
简单地说,它主要由具有 AutoPostBack 属性的控件使用
http:// /www.dotnetspider.com/resources/189-AutoPostBack-What-How-works.aspx
如果您想为自定义控件实现自动回发,那么您需要实现 IPostBackDataHandler
simply said, it is used mainly by controls with AutoPostBack property
http://www.dotnetspider.com/resources/189-AutoPostBack-What-How-works.aspx
if you want to implement autopostback for your custom control, then you need to implement IPostBackDataHandler
该解决方案可能有效,但并不是真正的解决方案。更好的方法是找出按钮事件未触发的原因并解决问题的核心。
现在回答您的问题。PostBack 是用于描述表单何时被提交(发布)回同一页面的术语。就这么简单。
普通的提交按钮就足够了,但回发的一部分是能够识别哪个控件触发了它,这意味着单击了哪个按钮或链接。
为了做到这一点,ASP.NET 会自动向表单添加隐藏字段,并且当单击应导致回发的元素时,JavaScript 代码用于将这些隐藏字段的值更新为正确的值,指示单击的内容 - 您传递的参数。
Microsoft 选择给执行上述操作的 JS 函数命名为 __doPostBack ,它只是函数的名称,是 ASP.NET 自动写入浏览器的普通 JavaScript 函数。
希望现在事情变得更清楚了。
The solution might be working but it's not a real fix.. better way will be to find why the button events are not triggering and fix the core of the problem.
Now to answer your questions.. PostBack is the term used to describe when the form is being submitted (posted) back to the same page. Simple as that.
Ordinary submit button would have been enough, but part of PostBack is the ability to identify which control triggered it, meaning what button or link was clicked.
To do such a thing
ASP.NET
is automatically adding hidden fields to the form and when clicking on element that should cause PostBack, JavaScript code is used to update the values of those hidden fields to the proper values indicating what was clicked - the argument you pass.The name Microsoft chose to give to the JS function doing the above is
__doPostBack
- it's just a name of a function, ordinary JavaScript function thatASP.NET
automatically writes to the browser.Hope things are bit more clear now.