ASP.NET UpdatePanel and Javascript __dopostback

主宰稳场 提交于 2019-12-03 07:46:06

If you want to put some value inside _EVENTARGUMENT you should do this with javascript before sending form by _doPostBack('UpdatePanel1','') because __EVENTTARGET is hidden field and in your html document it looks like this:

<input type="hidden" value="" id="__EVENTARGUMENT" name="__EVENTARGUMENT">

I recommend you to do something like this:

function setArgAndPostBack() {
    var arg = document.getElementById('__EVENTARGUMENT');
    var arg = document.getElementById("__EVENTARGUMENT");
    arg.value = 'something you want to put to server';
    __doPostBack('UpdatePanel1', '');
}

If you use jQuery it would be shorter:

function setArgAndPostBack() {
    $("#__EVENTARGUMENT").val('something you want to put to server');
    __doPostBack('UpdatePanel1', '');
}

If it doesn't work I would like to suggest you to put one hidden field inside Update panel:

<asp:UpdatePanel runat="server" ID="UpdatePanel1">
    <ContentTemplate>
        <asp:HiddenField ID="hdnData" value="" runat="server" />
        <!-- your content goes here -->
    </ContentTemplate>
</asp:UpdatePanel>

And then do the same work like above:

function setArgAndPostBack() {
    //Here hidden field is filled with your data
    $("#<%=hdnData.ClientID%>").val('something you want to put to server');
    __doPostBack('UpdatePanel1', '');
}

In first scenario you are able to get __EVENTARGUMENT in server side:

String args = Request["__EVENTARGUMENT"];

If first scenario doesn't work you can use something like that:

String args = hdnData.Value;//This works even in Page_Load function.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!