![](/img/trans.png)
[英]Setting MasterPage property from a custom control on a Content page
[英]Setting a property of an asp control and reloading the page with changes
我有一個復雜的問題,但我將嘗試以一種簡單的方式進行解釋。 我有一個帶有LinkButton
的母版頁。 單擊該按鈕后,它將在內容頁面中更改ListView
的DataSourceID
屬性。 問題是更改屬性值后,我使用Response.Redirect("contentpage.aspx");
加載頁面Response.Redirect("contentpage.aspx");
但這不會將我在屬性中所做的更改加載到頁面中。
MasterPage.aspx部分代碼
<asp:LinkButton
ID="Link_ClothesMen"
runat="server"
OnClick="Link_ClothesMen_Click">Men</asp:LinkButton>
MasterPage.aspx.cs部分代碼
protected void Link_ClothesMen_Click (object sender,EventArgs e)
{
ListView ListViewTemp = (ListView)ContentPlaceHolder1.FindControl("ListView1");
ListViewTemp.DataSourceID = "SqlDataSourceClothesMen";
Response.Redirect("ContentPage.aspx"); //This is wrong. Help here
}
ContentPage.aspx部分代碼
<asp:SqlDataSource ID="SqlDataSourceClothesMen" runat="server"
ConnectionString="Data Source=DESKTOP-1EGF4SE\SQLEXPRESS;Initial Catalog=clickstream;Integrated Security=True"
SelectCommand="select * from [ClothesMen]"></asp:SqlDataSource>
<asp:ListView ID="ListView1" runat="server" DataSourceID="" <!--I'm changing this property-->
GroupItemCount="3">
<LayoutTemplate>
<table style="table-layout:fixed;width:100%">
<tr id="groupPlaceholder" runat="server"></tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<td id="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td align="center">
<asp:Image runat="server" ImageUrl='<%# Eval("ImageUrl") %>' Height="20%" Width="70%" /><br />
<asp:Label ID="ProductTitleLabel" runat="server" Text='<%# Eval("ProductTitle") %>'></asp:Label><br />
<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>'></asp:Label><br />
</td>
</ItemTemplate>
<GroupSeparatorTemplate>
<tr runat="server">
<td colspan="3"><hr /></td>
</tr>
</GroupSeparatorTemplate>
</asp:ListView>
請幫幫我。 希望您對這個問題有個清楚的主意。
只需重定向列表視圖即可,而不是進行重定向(並且由於未通過響應重定向傳輸控制狀態,因此丟失了更改)。
ListViewTemp.DataBind();
單擊按鈕會導致回發到服務器,因此,如果這是您要為視圖更新的頁面上的唯一元素,則不需要完全重定向。
我想到了。 不需要Response.Redirect("ContentPage.aspx");
單擊LinkButton
本身會刷新頁面並進行更改。 解決了 在發布此問題之前,我應該考慮過這一點。 不管怎么說,還是要謝謝你!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.