0
如何通過在asp.net中回發來保持用戶控件的狀態? 我有一個用戶控件,它包含一個radTreeView,一個dropDownList和一個圖表和一個用於搜索的按鈕。在page_load中,我填充DropDownList和radTree和Chart。當我將用戶控件加載到我的page.aspx並選擇radTreeView或DropDownList的節點並單擊Buttn(btnSearch)時,用戶控件將丟失。如何保持用戶控件的狀態並將選定的節點或選定的值保存在dropDownList中???如何通過在asp.net中回發來保持用戶控件的狀態?
在MyUserControl.ascx
<asp:Label ID="lblProductGroup" runat="server" CssClass="h4" Text="products:"></asp:Label>
<telerik:RadTreeView ID="radTreeProduct" runat="server" ShowLineImages="true" Skin="WebBlue">
<WebServiceSettings Path="~/Services/WebService.asmx" Method="GetAllProductList"></WebServiceSettings>
</telerik:RadTreeView>
<div class="hundredW">
<asp:ImageButton ID="imgBtnSearch" runat="server" CssClass="h4" OnClick="imgBtnSearch_Click" />
</div>
<div>
<asp:Chart ID="chartInvoice" runat="server"
Palette="BrightPastel" ImageType="Png" BorderDashStyle="Solid" BackSecondaryColor="White"
BackGradientStyle="TopBottom" BorderWidth="2" BackColor="#D3DFF0" BorderColor="26, 59, 105"
Height="321px" Width="501px">
<BorderSkin SkinStyle="Emboss" />
<Legends>
<asp:Legend Name="Legend1" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"
IsTextAutoFit="False">
</asp:Legend>
</Legends>
<Titles>
<asp:Title Alignment="TopCenter" BackColor="180, 165, 191, 228" BackGradientStyle="TopBottom"
BackHatchStyle="None" Font="Microsoft Sans Serif, 12pt, style=Bold" Name="Title"
ToolTip="Revenue" ForeColor="26, 59, 105">
</asp:Title>
</Titles>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" BackColor="64, 165, 191, 228" BackSecondaryColor="White"
BorderColor="64, 64, 64, 64" ShadowColor="Transparent" BackGradientStyle="TopBottom">
<AxisY LineColor="64, 64, 64, 64" IsLabelAutoFit="False" ArrowStyle="Triangle">
<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
<MajorGrid LineColor="64, 64, 64, 64" />
</AxisY>
<AxisX IsLabelAutoFit="False" LineColor="64, 64, 64, 64" ArrowStyle="Triangle"
Interval="1">
<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" IsEndLabelVisible="False" Angle="0" />
<MajorGrid LineColor="64, 64, 64, 64" />
</AxisX>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
在MyUserControl.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillComboBox();//methode for Fill combobox
CreateRadTreeView();
CreateChart();
}
}
.............
在MuPage.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Control ucReport =this.LoadControl("~/UserControl/Repo/MyUserControl.ascx");
ucReport.EnableViewState = true;
content.Controls.Add(ucReport);
}
}
你已經動態添加了usercontrol,對不對? – 2014-09-20 06:20:22
是的。在我的頁面我動態地插入我的用戶控件 – user3628391 2014-09-20 07:24:34
@JayeshGoyani我正在編輯我的問題。 ypo能幫助我嗎? – user3628391 2014-09-20 07:53:52