Click here to Skip to main content
15,887,988 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
when i remove the update panel and script manager the javascript doesnt work .. the goal is to sending the selected calendar dates to the db which will be done in the web method, if i remove the update panel n scrpt manager the js works but with post back, i want to make the javascript work with the scriptmanger n updte panel any suggestions?


     <script type="text/javascript">
         $(function jScript () {
         $("[id*=btnApplyLeave]").bind("click", function () {

      
        var user = {};
        user.uname = $("[id*=txtUserName]").val();
        user.from = $("[id*=TextBox1]").val();
        user.to = $("[id*=TextBox2]").val();
        user.days = $("[id*=Label1]").val();
        user.purps = $("[id*=txtPurpose]").val();


        // user.propic = $("[id*=propicupload]").val();

        if (user.uname == '') {

            alert("Enter the Username!");
            return;
        }
        if (user.from == '') {

            alert("Select a Leave Start Date from the Calendar!");
            return;
        }
        if (user.to == '') {

            alert("Select a Leave End Date from the Calendar!");
            return;
        }
        if (user.purps == '') {

            alert("Enter the reason for requesting a leave!");
            return;
        }

        $.ajax({
            type: "POST",
            url: "RequestLeave.aspx/SaveUser",
            data: '{user: ' + JSON.stringify(user) + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                alert("Leave Request Sent!");
                window.location.reload();
            }
        });
        return false;


    });
});


</script> 


<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <contenttemplate>

from here until the closing tags of scrpt manger n update panel in between i just have asp calendars and text boxes and a submit button ('btnApplyLeave)

What I have tried:

i have tried to call the js again using
Sys.Application.add_load(jScript);
within the update panel but still didnt work
Posted
Comments
rmksiva 3-Apr-18 8:52am    
After adding update panel your control will be changed like UpdatePanel1_txtUserName so try to get $("#UpdatePanel1_txtUserName").val();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900