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.

4

1 回答 1

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>
于 2012-12-29T11:05:56.943 回答