user3492682
user3492682

Reputation: 17

To use hidden field value in another aspx file

In the below code i have a hidden value in sample.ascx and i want to use that value in sample.aspx in its codebehind.pls help me to do this.

Sample.ascx

txthidd.Value = "Hai";
<asp:HiddenField ID="txthidd" runat="server" />

Upvotes: 0

Views: 327

Answers (2)

Tomas Pastircak
Tomas Pastircak

Reputation: 2857

In the codebehind, you should create a property getting the field:

public string TxtHidText{
    get 
    {
        return txthidd.Value;
    }
}

Then, you'll reference it per the id, let's say you'll have something like this in ASPX:

<u1:Sample id="SomeSampleContentOfThePage" />

and in codebehind, it will be accessible via

var text = SomeSampleContentOfThePage.TxtHidText;

Note that if you want to set it from the other aspx, you should create a set part as well.

Upvotes: 1

yogi
yogi

Reputation: 19591

You can create a Public property in your ascx like this

public string txt
{
  get
  {
    return this.txthidd.Value;
  }
}

and can access this in aspx like this

string textOnAspx = UC_UserControl.txt;

Upvotes: 2

Related Questions