开发者

javascript __doPostBack doesn't seem to work for me

开发者 https://www.devze.com 2022-12-27 16:45 出处:网络
I use yui datatable in my asp.net application... I have a link button in one of my columns and it works fine but doesn\'t do a postback of a hidden button...

I use yui datatable in my asp.net application... I have a link button in one of my columns and it works fine but doesn't do a postback of a hidden button...

 myDataTable.subscribe("linkClickEvent", function(oArgs) {
            javascript: __doPostBack('ctl00_ContentPlaceHolder1_Button1', '');
            YAHOO.util.Event.stopEvent(oArgs.event);
        });

and in my page

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
   style="display:none;" />

 protected void Button1_Click(object sender, EventArgs e)
 {
    D开发者_StackOverflow社区ownloadFile(Hfhref.Value, true);
 }

I used break point but it doesn't seem to get the __dopostback.. Any suggestion...


add unique id on __doPostBackMethod from Button.


I just did this and it worked,

document.getElementById("ctl00_ContentPlaceHolder1_Button1").click();

just call click() my button it worked...

I want to know whether it works in all browsers...


If you're using ASP.Net 4.0 framework, add ClientIDMode="Static" to your control declaration and you can call __doPostBack('Button1',''); directly.

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
   style="display:none;" ClientIDMode="Static" />

The ClientIDMode attribute is new to 4.0 and allows you the option of having a known unique id for controls. Calling postback for the control will run whatever postback method is defined in the control's OnClick attribute.


In your markup, make sure to properly case the OnClick handler.

onclick="Button1_Click"

should be

OnClick="Button1_Click"

The way you have written it, onclick will be interpreted as an attribute of the control and onclick="Button1_Click" will be rendered to the browser, instead of being handled on the server side.

0

精彩评论

暂无评论...
验证码 换一张
取 消