明确__doPostBack() [英] Explicit __doPostBack()

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

问题描述

我已明确地对按钮的OnClientClick事件添加__doPostBack()。

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

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

当我点击按钮,在Page_Load中调用两次。 但是,如果我加入低于code里面的页面加载,加载页面上按一下按钮调用一次。

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','')");

同样地,如果我添加,返回虚假它给我就呼吁只有一次在点击页面加载

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是给我一次两次页面加载,但增加回报attribute.add code真或假是给同样的结果,只有一个页面加载的呼叫。

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渲染上与你的code和doPostBack客户端大小的点击数的功能。

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

因此​​,它被称为2倍,因为它的一个所谓的自我,一个是因为你补充说。

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

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

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