Search code examples
jquerytelerikwebusercontrol

jquery doesn't work in the second time loading webuser control


this is html code in webuser control

    <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0" Width="100%">
        <telerik:RadPageView ID="RadPageView1" runat="server">

        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <script type="text/javascript">
            $(function (){
            $('#btn_jquerycall').button().click(function () {
                alert("Comming Soon!");
            });
        });
    </script>
        <fieldset>
            <div style="margin-top: 10px; margin-left: 10px;">
                <span style="font-weight: bold;">
                    <asp:Literal runat="server" ID="lblSubject" />
                </span><span style="font-style: italic;">
                    <asp:Literal runat="server" ID="lblDate" Text=" - {0:dd/MM/yyyy}" />
                </span>
            </div>
            <div class="event">
                <asp:Literal runat="server" ID="lblContent" />
            </div>
        </fieldset>
        <div>
            <telerik:RadButton ID="telerik_button" runat="server" Text="Telerik Button" 
                    Height="35">
                    <Icon PrimaryIconUrl="~/Images/iconGreen.png" PrimaryIconWidth="32" PrimaryIconHeight="32"
                        PrimaryIconCssClass="PrimaryIcon" />
                </telerik:RadButton>
                <input id="btn_jquerycall" type="button" value="Alert Jquery"/>
        </div>
    </telerik:RadPageView>
</telerik:RadMultiPage>

the problem is that when the first time i load this page, Jquery work well when i click on btn_jquerycall button that means alert were called. But when i click on telerik_button this webuser control was loaded and in the second time loading when i click on btn_jquerycall again, jquery didn't called as well as i tried to move btn_jquerycall outside of RadMultipage..

How do i can work with jquery in the second time loading? Need help.....


Solution

  • Try this:

    The Script code should be in RadCodeBlock tag outside the RadMultiPage, like this :

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        $(document).ready(function (){
            $("#<%=btn_jquerycall.Client%>").click(function () {
                alert("Comming Soon!");
            });
        });
     </script>
    </telerik:RadCodeBlock>
    

    RadcodeBlock