Click here to Skip to main content
16,021,417 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I tried to store the output of a javascript function (Func() in my case) to a HiddenField in the SharePoint Master Page but the value that is assigned to the "Value" property of the hidden field is displayed as it is.
My code is,

(.master file)
ASP.NET
<head>
<script>
     function Func()
     {
     var msg="Hello";
     return msg;
     }
</script>
</head>

<body>
<form id="form1" runat="server">
<div>
 <asp:HiddenField ID="HidFieldID"; runat="server"; Value="Func()" />
 </div>
</form>
</body>

In the above code, I have called the javascript function in the Value property of HiddenField. And my code behind (C#) is,
C#
HiddenField lblHTMLHiddenField = (HiddenField)this.Page.Master.FindControl("HidFieldID");
if (lblHTMLHiddenField != null)
{
  Label1.Text = lblHTMLHiddenField.Value;
}

The hidden field in the master page is called but the value assigned to the label is "Func()" given in the Value property and not the result of Func().

Please help me to store the output of the function in the hidden field.


Thanks in advance.
Posted
Updated 2-Apr-13 3:58am
v2
Comments
ZurdoDev 2-Apr-13 7:14am    
Value is just a string, so it does not get executed. You just need to call the code somewhere and fill in the value.
Manjari Raj 2-Apr-13 8:17am    
Yes.. But how can I execute the function and store its value to the HiddenField? Any idea plsss?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900