Monday, March 26, 2012

Updating an UpdatePanel through a LinkButton command generated by a repeater

Hi everybody,

I would like to refresh an update panel when I click on a Linkbutton generated by a repeater that looks like this:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<li>
<asp:LinkButton ID="LinkButton1" runat="server" OnCommand="FilterByPrize" CommandName="filter" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "NameID")%>'>
<%# DataBinder.Eval(Container.DataItem, "Name")%> </asp:LinkButton>
</li>
</ItemTemplate>
</asp:Repeater>
The command called is the following:   
 protected void FilterByPrize(object sender, CommandEventArgs E){string connString ="connstring"; SqlConnection IVR =new SqlConnection(connString);string finalquery ="sqlquery " + E.CommandArgument.ToString() +" order by TimeStamp desc"; SqlDataSource2.SelectCommand = finalquery; SqlDataSource2.DataBind(); userData.DataBind();} 
The problem with this is that it reloads the whole page instead of only the update panel. Is there a way to refresh the updatepanel from a function in the c# code called from a linkbutton?
Thanks

MrClash,

The update panel has an Update() method that will do this. But I'm afraid that you are going to have register the linkbutton with the update panel. Take a look at this thread.

http://forums.asp.net/thread/1703456.aspx

Good luck! And feel free to provide some more details if this doesn't work.
Regards.

No comments:

Post a Comment