Bind asp.net control value to code behind function

I have a hidden field that I want to bind either to a function in the code page. I don't quite remember the exact syntax and I can't seem to find an answer via google. Is this code correct? Thank.

print("<asp:HiddenField ID="dummy" Value='<%#Getdummy() %>' runat="server" />");

      

+1


source to share


2 answers


The code you put in looks pretty good ...

Two step process: add a hidden field to markup

<asp:HiddenField ID="hdnId" runat="server" Value='<%# GetValue() %>'/>

      



Then create the specified method signature ...

protected string GetValue()
{
   return "something";
}

      

Hope it helps ...

+2


source


If you have a hidden field with a runat = server, you can write code to assign the value in the code behind (not in the markup).



0


source







All Articles