admin管理员组文章数量:1336631
I have a user control with a public method:
public void ShowDetails(Guid requestGuid)
{
Label1.Text = reportGuid.ToString(); //only for testing
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "ShowEmailPreview", "alert('hi');", true);
//ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowEmailPreview", "alert('hi');", true); //doesn't work
//Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowEmailPreview", "alert('hi');", true); //doesn't work
}
When hosting page for this user control calls ShowDetails(), I need to call some javascript.
I tried with ScriptManager.RegisterStartupScript and Page.ClientScript.RegisterStartupScript but it doesn't work... However if I add an UpdatePanel on my control and add script for UpdatePanel as shown above, it works well.
I don't want to add UpdatePanel onto my control just for the sake of calling javascript.
Am I missing something?
Thank you!
I have a user control with a public method:
public void ShowDetails(Guid requestGuid)
{
Label1.Text = reportGuid.ToString(); //only for testing
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "ShowEmailPreview", "alert('hi');", true);
//ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowEmailPreview", "alert('hi');", true); //doesn't work
//Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowEmailPreview", "alert('hi');", true); //doesn't work
}
When hosting page for this user control calls ShowDetails(), I need to call some javascript.
I tried with ScriptManager.RegisterStartupScript and Page.ClientScript.RegisterStartupScript but it doesn't work... However if I add an UpdatePanel on my control and add script for UpdatePanel as shown above, it works well.
I don't want to add UpdatePanel onto my control just for the sake of calling javascript.
Am I missing something?
Thank you!
Share Improve this question asked Apr 14, 2011 at 10:29 inutaninutan 10.9k29 gold badges89 silver badges129 bronze badges2 Answers
Reset to default 8Actually changing your code as following should work.
ScriptManager.RegisterStartupScript(this.Page, typeof(System.Web.UI.Page), "ShowEmailPreview", "alert('hi');", true);
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ScriptName", "alert('hi');", true);
this is a shorter version
本文标签: ASPNetCalling javascript in User Control server side methodStack Overflow
版权声明:本文标题:ASP.Net - Calling javascript in User Control server side method - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742391797a2466134.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论