Run JavaScript code at ASP.NET page load

Posted by vaibhav on Stack Overflow See other posts from Stack Overflow or by vaibhav
Published on 2010-05-26T05:31:36Z Indexed on 2010/05/26 5:41 UTC
Read the original article Hit count: 290

Filed under:
|
|
|

I have a radiobox <asp:RadioButtonList CssClass="list" Style="width: 150px" ID="rdo_RSD_ExcerciseRoT" runat="server" Font-Bold="false" RepeatDirection="Horizontal" RepeatLayout="Table" TextAlign="Left" > <asp:ListItem Text="Yes" onclick="en();" Value="Y"></asp:ListItem> <asp:ListItem Text="No" onclick="dis();" Value="N" Selected="True"></asp:ListItem> </asp:RadioButtonList>

AS you may see second listitem is selected by default. But issue is, when my page is getting load dis() is not getting called. I want to run dis() on page load too.

I tried google, some blogs suggest the use of Page.RegisterStartupScript Method. But I dont exactly know what is the problem and why we should use this above mentioned method. I would appreciate if someone please tell me why this function is not getting called and how to call it.

Edit: I am giving Javascript code also, if it helps.

    <script type="text/javascript">
    function dis()
    {
        ValidatorEnable(document.getElementById('<%=RequiredFieldValidator32.ClientID%>'), false);
    }

    function en()
    {
        ValidatorEnable(document.getElementById('<%=RequiredFieldValidator32.ClientID%>'), true);
    }


</script>

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET