Metager [Bot]
New Member
My application is in asp.net 4.0, in that i am adding ascx control using jquery. user control is having one text box and button. on submit of this i want to save text in database. but when i click on submit button page gives error 404 as shown bellow also when i see source of page i don`t see those controls, but when i check them using firebug those are on page.can you please where i am going wrong or what changes i need to do to make this working. Thanks in Advance!!following is my code:
code on aspx page:\[code\] <%@ Page Title="Home Page" Language="C#" MasterPageFile="./Site.master" AutoEventWireup="true"CodeFile="LoadControl.aspx.cs"Inherits="LoadControl" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> <script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"> </script> <script type="text/javascript" src="http://github.com/malsup/blockui/raw/master /jquery.blockUI.js?v2.34"></script> <script type="text/javascript"> $(document).ready(function () { $('#Button1').click(function () { //$.blockUI({ message: '<h1> Processing...</h1>' }); var ControlName = "WebUserControl.ascx"; $.ajax({ type: "POST", url: "LoadControl.aspx/Result", data: "{ controlName:'" + ControlName + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { // $.unblockUI(); $('#result').html(response.d); }, error: function (msg) { // $.unblockUI(); alert(msg); $('#result').html(msg.d); } }); }); }); </script> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <p> <input type="button" id="Button1" value="http://stackoverflow.com/questions/14440018/Load Control" /> <div id="result"> </div> </p> </asp:Content>\[/code\]Code on usercontrols ascx page:\[code\] <%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> <h2>Web user control</h2> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="fnGetText();" /> </asp:UpdatePanel> Code on aspx .cs page public partial class LoadControl : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public static string Result(string controlName) { return Results(controlName); } public static string Results(string controlName) { try { Page page = new Page(); UserControl userControl = (UserControl)page.LoadControl(controlName); userControl.EnableViewState = false; 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 on ascx.cs file public partial class WebUserControl : System.Web.UI.UserControl { protected void Button1_Click(object sender, EventArgs e) { Response.Write("Text box value is " + TextBox1.Text); } }/// web.config <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0"/> </system.web> </configuration>\[/code\]Please tell me where i am going wrong or how can i achieve this thanks once again!!!!!!!!!
code on aspx page:\[code\] <%@ Page Title="Home Page" Language="C#" MasterPageFile="./Site.master" AutoEventWireup="true"CodeFile="LoadControl.aspx.cs"Inherits="LoadControl" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> <script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"> </script> <script type="text/javascript" src="http://github.com/malsup/blockui/raw/master /jquery.blockUI.js?v2.34"></script> <script type="text/javascript"> $(document).ready(function () { $('#Button1').click(function () { //$.blockUI({ message: '<h1> Processing...</h1>' }); var ControlName = "WebUserControl.ascx"; $.ajax({ type: "POST", url: "LoadControl.aspx/Result", data: "{ controlName:'" + ControlName + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { // $.unblockUI(); $('#result').html(response.d); }, error: function (msg) { // $.unblockUI(); alert(msg); $('#result').html(msg.d); } }); }); }); </script> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <p> <input type="button" id="Button1" value="http://stackoverflow.com/questions/14440018/Load Control" /> <div id="result"> </div> </p> </asp:Content>\[/code\]Code on usercontrols ascx page:\[code\] <%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> <h2>Web user control</h2> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="fnGetText();" /> </asp:UpdatePanel> Code on aspx .cs page public partial class LoadControl : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public static string Result(string controlName) { return Results(controlName); } public static string Results(string controlName) { try { Page page = new Page(); UserControl userControl = (UserControl)page.LoadControl(controlName); userControl.EnableViewState = false; 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 on ascx.cs file public partial class WebUserControl : System.Web.UI.UserControl { protected void Button1_Click(object sender, EventArgs e) { Response.Write("Text box value is " + TextBox1.Text); } }/// web.config <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0"/> </system.web> </configuration>\[/code\]Please tell me where i am going wrong or how can i achieve this thanks once again!!!!!!!!!