Accessing value of a hidden field on Masterpage from codebehind

后端 未结 4 559
失恋的感觉
失恋的感觉 2021-01-06 16:40

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

4条回答
  •  星月不相逢
    2021-01-06 17:16

    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 in your HTML.

提交回复
热议问题