Hidden field - cast

Posted on 2009-02-09
Last Modified: 2012-05-06
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'.
Question by:johnkainn
    1 Comment
    LVL 16

    Accepted Solution

    Try this
    HtmlInputHidden h = (HtmlInputHidden)ProjectSubjectAgeWUC1.FindControl("hidText");

    Open in new window


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now