[C#] jQuery Call Ascx
jQuery
$(document).ready(
function
() {
LoadUserCOntrol();
});
function
LoadUserCOntrol() {
var
ControlName =
"UserControls/Common_UC.ascx"
;
$.ajax({
type:
"POST"
,
url:
"CustomBooking.aspx/Result"
,
data:
'{ "controlName":"'
+ ControlName +
'"}'
,
contentType:
"application/json; charset=utf-8"
,
dataType:
"json"
,
async:
false
,
success:
function
(response, Control) {
$(
'#sortable'
).append(response.d);
},
error:
function
(msg) {
alert(msg);
$(
'#sortable'
).html(msg.d);
}
});
}
c# behind
[WebMethod]
public
static
string
Result(
string
controlName)
{
//Thread.Sleep(2000);
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(userControl);
StringWriter textWriter =
new
StringWriter();
HttpContext.Current.Server.Execute(page, textWriter,
false
);
return
textWriter.ToString();
}
catch
(Exception ex)
{
return
ex.ToString();
}
}