views:

2352

answers:

3

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.

A: 

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.

Matthew Steeples
I tried to call it like this __doPostBack('<%=UpdatePanel1.ClientID%>','');Is that how to call the method?
Eric
-1: calling __doPostBack directly is bad practice.
DDaviesBrackett
A: 

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.

DDaviesBrackett
I'm not sure I understand how to use this.this was my attempt:btnedit.OnClientClick = ClientScript.GetCallbackEventReference(UpdatePanel1, "", "", "") return false;", hidden.ClientID)I'm not sure what to put as parameters.
Eric
I've edited my answer to point out that you probably want a postback and not a callback.
DDaviesBrackett
I'm slightly confused about what you're trying to do - does the user do something with the result of openModal(), and it's after they've done that you want the listbox to rebind?
DDaviesBrackett
A: 

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);
}
Ricky Supit