adding user control into updatepanel using ajax jquerry

prednisone

New Member
I have a page with a large gridview with many columns. When the user click on a cell I load in a div popup the content of an user control using ajax jquerry. That control has a gridview with add/edit/delete options I want that control to be able to do asyncrouns postback inside that div/popup. I tried using an updatepanel inside user control, or on the main page wraping the div/popupuser control:\[code\]<%@Control Language="C#" AutoEventWireup="true" CodeBehind="RecruitmentFormPopUp.ascx.cs" Inherits="WorkforcePlanner.UserControls.RecruitmentFormPopUp"%><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional"><ContentTemplate><asp:GridView ID="GridViewRequestEdit" runat="server" ondatabinding="GridViewRequestEdit_DataBinding" AutoGenerateColumns="false" EnableViewState="true"><Columns><asp:TemplateField><ItemTemplate> </ItemTemplate> </asp:TemplateField><asp:BoundField DataField="Name" HeaderText="Name"/><asp:BoundField DataField="City" HeaderText="City" ReadOnly="true"/><asp:CommandField ShowDeleteButton="True" EditText="Modifier" DeleteText="Supprimer" CancelText="Annuler" ShowEditButton="True" CausesValidation="false" UpdateText="Ajoute"/> </Columns> </asp:GridView></ContentTemplate> </asp:UpdatePanel>\[/code\]main page:\[code\]<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="alin.aspx.cs" Inherits="WorkforcePlanner.alin" EnableViewStateMac="false" %><asp:GridView ID="GridViewRequestForm" CssClass="gridViewRequestForm" runat="server" AutoGenerateColumns="True" OnSelectedIndexChanged="showPopup" OnRowCreated="GridViewRequestForm_OnRowCreated"><script type="text/javascript"> $(document).ready(function () { $(".gridViewRequestForm td").click(function () { var col = $(this).parent().children().index($(this)); var row = $(this).parent().parent().children().index($(this).parent()); var grade = $(".rowGridClass tr").eq(row - 1).find('td').eq(0).html(); $.ajax({ type: "POST", url: "Alin.aspx/Result", data: "{ controlName:'RecruitmentFormPopUp.ascx',parametruGrade:'" + grade + "',parametruWeekNo:'31',parametruUserId:'22'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { $('#result').html(response.d); //$('#result').contents().append(response.d); //alert($('#result').html()); $("#overlay").show(); $("#result").fadeIn(300); $("#overlay").unbind("click"); }, error: function (msg) { // $.unblockUI(); alert("EROARE"); ///$('#result').html(msg.d); } }); }) })</script>\[/code\]main page .csin main page the json call is handled by the webservice:\[code\] [WebMethod] public static string Result(string controlName, string parametruGrade, int parametruWeekNo, string parametruUserId) { return Results(controlName, parametruGrade, parametruWeekNo, parametruUserId); } public static string Results(string controlName, string parametruGrade, int parametruWeekNo, string parametruUserId) { try { Page page = new Page(); RecruitmentFormPopUp userControl = (RecruitmentFormPopUp)page.LoadControl(controlName); userControl.ParametruFirst = parametruGrade; userControl.ParametruSecond = parametruWeekNo; userControl.ParametruThird = parametruUserId; HtmlForm form = new HtmlForm(); form.Controls.Add(userControl); page.Controls.Add(form); StringWriter textWriter = new StringWriter(); HttpContext.Current.Server.Execute(page, textWriter, false); return textWriter.ToString(); } catch (Exception ex) { return ex.ToString(); } }\[/code\]So on cell click on main page on one cell of the main grid view,an ajax call is made,and the server is creating the html of the user control. Is rendering the gridview,but when i clik con the edit buton of the gridview inside the control i want the usercontrol to asyncrounous post back to edit. Why ? let's say tomorow i want to add a listbox in that popup where is loaded the user control, I will only have to add the listbox in control,and the design is updated. now i get error: Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Also i had to put EnableViewStateMac="false" cause if the gridview inside the user control will fire an page postback not partial, server sees that i'm adding extracontrols to page. Any idea avoiding using viewstatmac="false"It's all about injecting user control html server generated inside an page.Any idea, did somebody added an user control with ajax call,and inserted in an updatepanel to postback partial the page?
 
Back
Top