问题
I am using a RadTabStrip for 2 tabs. I would like OnTabClick for the tab to do an update of the updatepanel on the page. The problem I am having is its not finding the control on the child page.
My logic for the parent page
protected void tabClick(object sender, RadTabStripEventArgs e)
{
if (e.Tab.SelectedIndex == 0)
{
UpdatePanel tab1 = (UpdatePanel)Page.FindControl("up_EntirePage_Tab1");
tab1.Update();
}
else
{
UpdatePanel tab2 = (UpdatePanel)Page.FindControl("up_EntirePage_Tab2");
tab2.Update();
}
}
So up_EntirePage_Tab1 and up_EntirePage_Tab2 look like this on their respected pages.
<asp:UpdatePanel ID="up_EntirePage_Tab1" runat="server">
<asp:UpdatePanel ID="up_EntirePage_Tab2" runat="server">
and the RadTabStrip looks like so on the parent page
<telerik:RadTabStrip ID="RadTabStrip1" runat="server" SelectedIndex="0"
Height="100%" MultiPageID="RadMultiPage1" OnTabClick="tabClick">
<Tabs>
<telerik:RadTab runat="server" PageViewID="t1" Text="Assign Events To Categories" >
</telerik:RadTab>
<telerik:RadTab runat="server" PageViewID="t2" Text="Assign User Types To Events"
Selected="True">
</telerik:RadTab>
</Tabs>
</telerik:RadTabStrip>
Not sure what I need to do in order to make this happen.
Pretty much on Tab 1 I have a list that if I add to it, it will update fine. Now if I was to click on tab 2 that contains the same list it will not be updated. So I figure calling the updatepanel on the respected pages to update when switching should pull the correct information for the page.
If there is an easier method or even more optimal method I would appreciate the help but for now my current method won't even work. I am getting a null reference because my find control can't find the updatepanel.
EDIT: The updatepanels are in the usercontrols tabs1 and tab2. They are two separate user controls.
回答1:
Ok , In your usercontrol you need to create property for UpdatePanel on both UserControls.
For Tab1 on Usercontrol1
public UpdatePanel Tab1UpdatePanel
{
get
{
return up_EntirePage_Tab1;
}
set
{
up_EntirePage_Tab1 = value;
}
}
for Tab2 on UserControl2
public UpdatePanel Tab2UpdatePanel
{
get
{
return up_EntirePage_Tab2;
}
set
{
up_EntirePage_Tab2 = value;
}
}
Now you have property for both Updatepanel , Now you can use them and do whatever you want with it.
protected void tabClick(object sender, RadTabStripEventArgs e)
{
if (e.Tab.SelectedIndex == 0)
{
UserControl1.Tab1UpdatePanel.Update();
}
else
{
UserControl2.Tab2UpdatePanel.Update();
}
}
回答2:
If I understand your question correctly 1. The Update Panel is in the parent page (Hope fully a aspx page) 2. The Tabs are in child Page (Hope fully a user control)
You wanted to refresh the Update Panel in aspx, if the Tab is clicked.
Try the following Step 1: Expose a Event from your child page / user control. Step 2: Attach a Even handler to the Child Page event in your parent page. Step 3: Call the Event in your Child Control, so this will trigger the event / handler Step 4: In the Parent page, refresh the Update panel.
Hope that works.
来源:https://stackoverflow.com/questions/19105602/call-child-control-on-parent-page-for-an-update-of-an-updatepanel