我的ascx代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Demo.ascx.cs" Inherits="Demo" %>
<asp:HiddenField ID="hidden1" runat="server" Value=""/>
<asp:Label ID="lbl1" runat="server" Text="Hiii"></asp:Label>
我的ascx.cs代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lbl1.Text = "Mahendra Kamble";
hidden1.Value = "123";
}
}
我的aspx代码:
<%@ Register TagName="TopBar" TagPrefix="CRS" Src="~/Demo.ascx" %>
---
--
<div>
<CRS:TopBar ID="Hide" runat="server" Visible="false"/>
</div>
我的aspx.cs代码
if (!IsPostBack)
{
//Label lb = (Label)Hide.FindControl("lbl1");
// Response.Write("---" + lb.Text);
//HiddenField hf = (HiddenField)Hide.FindControl("hidden1");
//Response.Write("---" + hf.Value);
// UserControl control = (UserControl)LoadControl("Demo.ascx");
Demo uc = (Demo)Page.LoadControl("Demo.ascx");
// HiddenField hf1 = (HiddenField)control.FindControl("hidden1");
HiddenField hide = (HiddenField)uc.FindControl("hidden1");
Response.Write("--- " + hide.Value + " Value ");
form1.Controls.Add(uc);
}
现在我应该如何在这个aspx.cs页面中获取HiddenField的值,即hidden1.value =“123”?
答案 0 :(得分:0)
您可以将隐藏字段的值传递给视图状态属性。 所以你可以设置或获取隐藏字段的值。