i m trying to load user control ( a grid view) with jquery . but is not working here is my code :
default.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#Button1').click(function () {
var control = "WebUserControl.ascx";
$.ajax({
type: "POST",
url: "Default.aspx/GetUserControl",
data: "{userControl:'" + control + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
$('#div1').html(r.d);
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="Button1" value="Load Data from User Control" />
<div id="div1"></div>
</div>
</form>
</body>
</html>
[WebMethod]
public static string GetUserControl(string userControl)
{
Page page = new Page();
UserControl control = (UserControl)page.LoadControl(userControl);
HtmlForm form = new HtmlForm();
form.Controls.Add(control);
page.Controls.Add(form);
StringWriter writer = new StringWriter();
HttpContext.Current.Server.Execute(page, writer, false);
return writer.ToString();
}