Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have written and coded all the function using asp.net ajax in which on categories listbox item change it autopostbacks and show the related subcategories listbox w.r.t category listbox selected item.

I want to do it in jquery.

How i can do it using ajax.

Thanks

Following is the markup :
JavaScript
$('#UpdatePanel1').panelReady(function () {
                           $('#lstcategory').click(function () {
                               //$("input#text1").val($("#lstcategory option:selected").val());
                               //var dataToSend = { MethodName: 'GenerateSubCategories', Category: $("#lstcategory option:selected").val() };
                               var dataToSend = { MethodName: 'GenerateSubCategories', Category: document.getElementById('lstcategory').value };
                               // var id = $.readQS('productId');
                               var options =
                                   {
                                       url: <%=Request.Url %>,
                                       data: dataToSend,
                                       dataType: 'JSON',
                                       type: 'POST',
                                       success: function () { $(this).dialog("close"); }
                                   };
                               $.ajax(options);
                           });
                       });


                   });

asp code :
ASP.NET
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                             <contenttemplate>
                             <asp:ListBox ID="lstcategory" ClientIDMode="Static" runat="server" AutoPostBack="True"
                         Font-Bold="True" Font-Names="Arial" Font-Size="10pt" Height="150px" Width="220px"
                                     onselectedindexchanged="lstcategory_SelectedIndexChanged">
                         <asp:ListItem>None

                    <asp:ListBox ID="lstsubcategory" runat="server" ClientIDMode="Static"  AutoPostBack="True"
                         Height="150px" onselectedindexchanged="lstsubcategory_SelectedIndexChanged"
                         style="text-align: left" Visible="False" Width="220px">
                     <asp:Button ID="btngenerate" runat="server" onclick="btngenerate_Click"
                         Text="Generate Form" /></contenttemplate>
                         <triggers>
                         <asp:AsyncPostBackTrigger ControlId="lstcategory" />
                         <asp:AsyncPostBackTrigger ControlID="lstsubcategory" />
                         </triggers>

And c# code behind :
C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Form["MethodName"] == "GenerateSubCategories")
        {
            var category = Request.Form["Category"].ToString();
            GenerateSubCategories(category);
        }
        if (Request.Form["MethodName"] == "GenerateForm")
        {
            var subcategory = Request.Form["SubCategory"].ToString();
            GenerateForm(subcategory);
        }

I am getting form method name as hashed code or id get mangled.

Instead if getting "GenerateSubCategories".
Posted
Updated 22-Mar-12 16:14pm
v3
Comments
ZurdoDev 21-Mar-12 8:01am    
Please be more clear on what you want.
[no name] 22-Mar-12 8:20am    
Hi , I have updated plz have a look

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