У меня есть usercontrol, что я хочу передать значение с моей страницы.aspx. Я установил свойство в usercontrol для установки значения, которое мне нужно со страницы, но значение всегда равно нулю.
Вот мой управляющий код на странице.aspx,
<tcs:SubmitDataDiscrepancy runat="server" ID="SubmitDataDiscrepancy" EntityNameProp='<%# Bind("Association_Name") %>'/>
код.ascx,
<div style="text-align:right;">
<asp:LinkButton ID="ReportLink" runat="server" Text="Report data discrepancy"></asp:LinkButton>
<asp:Panel ID="ReportPanel" runat="server" CssClass="modalPopup" style="width:auto;">
<div id="PopHeader" style="background-color: black; color: white; height: auto;">
Report discrepancy
<div style="float: right;">
<asp:LinkButton runat="server" ID="AssociationCancelTextButton" CausesValidation="False" Font-Underline="false"
CssClass="glyphicon glyphicon-remove white" ToolTip="Close" />
</div>
</div>
<div style="margin:10px;">
<div>
Submit change request for: <asp:Label ID="EntityName" runat="server" />
</div>
<div>
<textarea id="reportTextArea" runat="server" class="form-control" style="height: 100px; margin-bottom:10px; width: 100%;"></textarea>
<button id="reportSubmitButton" runat="server" class="btn btn-primary" type="submit">Submit</button>
</div>
</div>
и страница.ascx.cs,
public partial class SubmitDataDiscrepancy : System.Web.UI.UserControl
{
public string EntityNameProp { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
EntityName.Text = EntityNameProp;
}
}
Почему я не получаю значение, которое я ожидаю от страницы.aspx?
Все переменные расположены в конце жизненного цикла страницы, что не имеет аналогов в HTTP. Поэтому вам нужен способ сохранить свою собственность. Например, вы можете использовать ViewState
, Session
или HiddenField
(Другие способы).
В этом случае имеет смысл просто использовать Label.Text
:
public partial class SubmitDataDiscrepancy : System.Web.UI.UserControl
{
public string EntityNameProp {
get { return EntityName.Text; }
set{ EntityName.Text = value; }
}
}