asp.net - how can I reload an update panel onclient side using javascript? - Stack Overflow

I have a gridview button that I programmatically created and I want to load an update panel on the clie

I have a gridview button that I programmatically created and I want to load an update panel on the client side with the sent data. I have a hidden value field that gets its data on the click of the gridview button and the dropdownlist in my updatepanel depends on that value.

I have a gridview button that I programmatically created and I want to load an update panel on the client side with the sent data. I have a hidden value field that gets its data on the click of the gridview button and the dropdownlist in my updatepanel depends on that value.

Share asked May 27, 2009 at 17:00 EricEric 8,09819 gold badges101 silver badges131 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 1

while calling __doPostBack directly will work, it's not a perfect solution because the name of that function is strictly speaking an implementation detail of the .Net framework.

A better solution is to use ClientScriptManager.GetPostBackEventReference, which gives you a more resilient interface to the same functionality. Do note that GetPostBackEventReference and GetCallBackEventReference are not the same thing - the former causes a page reload (partial or full, depending on how your UpdatePanels are set up), while the latter doesn't.

The easiest way to do this is to call __doPostBack from client side.

On client side button1_onclick method, calls:

__doPostBack('<%=UpdatePanel1.ClientID %>','Refresh:0,1,2');    //refresh update panel

On page behind add the following event handler to capture the post back call:

protected void UpdatePanel1_Load(object sender, EventArgs e)
{
    string arg = Request.Form["__EVENTARGUMENT"];

    if (string.IsNullOrEmpty(arg)) return;

    if (arg.StartWith("Refresh")
    {
         //parse data first then do your thing here...
    }
}

And of course don't forget to wire event to the above method:

protected void Page_Init(object sender, EventArgs e)
{           
    UpdatePanel1.Load += new EventHandler(UpdatePanel1_Load);
}

we use the __dopostback() method which simulates a postback and causes the updatepanel to refresh

__doPostBack('controlName','');

Don't forget that the control name is it's HTML ID (which may well contain dollars etc) and not just it's ASP.NET ID.

As far as I know you can either call this method and pass in the hidden value field, or the div that it is in.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744912986a4600664.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信