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
  • 40,727
  • 45
  • 159
  • 271
MonaliJ
  • 213
  • 2
  • 4
  • 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
  • 18,398
  • 3
  • 51
  • 64