In a follow up to my previous question, I want to get the value of the hidden input field from the child page codebehind.
I tried HtmlInputHidden hdnID = (H
You should create a property in Masterpage which wrap the HiddenField.
public String HdnFieldValue
{
get
{
return hidField.Value;
}
set
{
hidField.Value = value;
}
}
And in page code behind you can access it like this:
((YourCustomMaster)Page.Master).HdnFieldValue
If something is not clear please ask me.
So change it FROM
HtmlInputHidden hdnID = (HtmlInputHidden)Page.Master.FindControl("ctl00_hdnField");
TO
HiddenField hdnID = (HiddenField)Page.Master.FindControl("hdnField");
It's just a casting thing - notice HtmlInputHidden
changed to HiddenField
. You also don't need the ct100_
part - this is just so the HTML rendered element has a unique ID.
The control on your page is an asp.net control, not a generic HTML control.
You would use HtmlInputHidden
if you put a generic <input type="hidden" />
in your HTML.
I don't think you need to prefix the hidden field's ID with ctl00_
, just use the normal ID:
(HtmlInputHidden)Page.Master.FindControl("hdnField");
Use something like:
if (Page.Master.FindControl("hdnField") != null)
{
String myValue = (HtmlInputHidden)Page.Master.FindControl("hdnField").value;
}