• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1225
  • Last Modified:

Hidden field - cast

I have a web user control in an aspx page.
I want to access a hidden field that is in the web user control.
To access a value from TextBox I do following in code behind of the aspx page:
TextBox h=(TextBox)MyWUC1.FindControl("TextBox1");
string myText = Convert.ToString(h.Text);

How would I get the value from a hidden inputfield that is in the web user control?
If I try following:

HiddenField h = (HiddenField)ProjectSubjectAgeWUC1.FindControl("hidText");

Then I get following error: Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlInputHidden' to type 'System.Web.UI.WebControls.HiddenField'.
1 Solution
Try this
HtmlInputHidden h = (HtmlInputHidden)ProjectSubjectAgeWUC1.FindControl("hidText");

Open in new window


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now