Thanks Stilgar solved my problem. I just create a js file and write all my codes into it after i added this file to UserControl and after i get this UserControl's html i use $("#DivID").html(UserControlHTML); Its working now.
Hi everyone;
Im using Ajax and Webservice to load UserControls. Its ok i can easily get the html code of UserControl but there is a problem.
For example UserControl's html code is something like that.
<h3>Header</h3>
<div id="content">
<p>lorem ipsum dolor sit amet...</p>
</div>
<script type="text/javascript">
alert("This is a message");
</script>
<h3>Footer</h3>
Javascript codes that requesting html code of usercontrol
(usage UserControlYukle("UserControls/Article.ascx"); )
//This is a function that i request UserControl's html code from WebService
function UserControlYukle(ControlPath) {
PersonalWebPage.Services.LoadUserControl.GetControlHtml(ControlPath, Success, Failed);
}
function Success(result) {
var RsltElem= $get("Icerik");
RsltElem.innerHTML = result;
}
function Failed(error) {
alert(error.get_message());
}
Webservice Codes (LoadUserControl.asmx)
//This is the code block which is in WebService
//and returning back UserControl's html code.
public string GetControlHtml(string controlLocation)
{
Page page = new Page();
UserControl userControl = (UserControl)page.LoadControl("~/UserControls/" + controlLocation);
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();
}
When i get this html code and insert it to an div's innerHTML. html looking as it should. But javascript codes which written on usercontrol not working. It should give me alert but its not.