最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - javascript __doPostBack doesn't seem to work for me - Stack Overflow

programmeradmin4浏览0评论

I use yui datatable in my asp 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)
 {
    DownloadFile(Hfhref.Value, true);
 }

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

I use yui datatable in my asp 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)
 {
    DownloadFile(Hfhref.Value, true);
 }

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

Share Improve this question asked Apr 16, 2010 at 12:18 ACPACP 35.3k101 gold badges233 silver badges373 bronze badges 2
  • @Panidiya Why you have type on front javascript: ? – Aristos Commented Apr 16, 2010 at 12:21
  • @Aristos releasing that too didnt work.. – ACP Commented Apr 16, 2010 at 12:23
Add a ment  | 

4 Answers 4

Reset to default 3

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)

  1. 暂无评论