0

I have webapplication in c# asp.net 4.0

I have User Control in that I have written javascript :-

<script>
    function SetValue() {        
        alert(document.getElementById('offSetClient').value);
    }
</script>

<asp:HiddenField ID="clientDateTime" runat="server" />
<asp:HiddenField ID="offSetClient" runat="server" Value="Test"/>

and this User Control added into a web form. Please suggest me how can I call this javascript on User Control page load.

Mr_Green
  • 39,139
  • 43
  • 154
  • 250
MonaliJ
  • 193
  • 1
  • 3
  • 11

1 Answers1

0

You can use Page.ClientScript.RegisterStartupScript to attain this.

protected void Page_Load(object sender, EventArgs e)
{
   Page.ClientScript.RegisterStartupScript(GetType(), "ShowAlert", "SetValue('" + offSetClient.ClientID + "');", true);
}

Please add an input parameter for the function to get the object of hidden field and pass the same from function.

<script type="text/javascript">
  function SetValue(objHdn) {
    alert(document.getElementById(objHdn).value);
  }
</script>
TechDo
  • 17,954
  • 3
  • 48
  • 63