Saturday, March 10, 2012

User Controls and refresh

why not just have one button that refreshes the whole page, therefore refreshing both user controls.

hth,

mcm


I am using asp.net ajax and <asp:updatePanel> on the user control where contains textboxes and button but not on the usercontrol which contains only labels. Page is only refreshing the user control having text boxes. I also somhow programatically refresh the 2nd user control.

All you need to do is create a method in the codebehind for the second usercontrol. In that method, call the .Update() method of the updatepanel. Then just call that method from your other usercontrol.

http://dotnetjunkies.com/Tutorial/1DC595C5-B34D-432B-B78E-93FFEF1FC2FE.dcik


Thanks for the response. But can you please give an example or modify my attached code. I have just atttached the main page with two user control "Input" & Display.

Main Page Code<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" /><table><td> <Sales:Input ID="ucMonthTY" runat="server" /></td><td> <Sales:Display ID="ucQuarterTY" runat="server" /></td></table>User Control with text box and button
<asp:UpdatePanel ID="upPanelSales" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:TextBox ID="txtRegularMix" runat="server" MaxLength="4" Columns="4" CssClass="defaulttxt" /> <asp:Button ID="btnReCalc" runat="server" Text="Recalc." CommandName="Calculate" CommandArgument="ReCalc" OnCommand="Calculate" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnReCalc" EventName="Command" /> </Triggers></asp:UpdatePanel>User Control with labels only<asp:Label ID="lblRegularSales" runat="server" CssClass="default" />
Thanks again 
 


You have to use UdatePanel2.Update() for 2nd user control


I achieved this using an Event. Here is the updated code

User Control with text boxes, Add an event

Public Event ReCalculation(ByVal sender As Object)

On button click add the following statement

RaiseEvent ReCalculation(Me)

User control with label control, add an update panel

<asp:UpdatePanel ID="upSales" runat="server" UpdateMode="Conditional" >

<asp:Label ID="lblRegularSales" runat="server" CssClass="default" />

</asp:UpdatePanel>

On the main page add the following code for the user control1, where ucTYMonth1 is the usercontrol id for the first user control

Protected Sub ucTYMonth1_ReCalculation(ByVal sender As Object) Handles ucMonth1TY.ReCalculation
Dim pnl As UpdatePanel = CType(Me.ucSalesTotal.FindControl("upSales"), UpdatePanel)
pnl.Update()
End Sub

No comments:

Post a Comment