ASP.Net-在用户控制服务器端方法中调用javascript

| 我有一个带有公共方法的用户控件:
    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
    }
当此用户控件的托管页面调用ShowDetails()时,我需要调用一些javascript。 我尝试使用ScriptManager.RegisterStartupScript和Page.ClientScript.RegisterStartupScript,但是它不起作用...但是,如果我在控件上添加UpdatePanel并为如上所述的UpdatePanel添加脚本,则效果很好。 我不想只是为了调用javascript而将UpdatePanel添加到我的控件中。 我想念什么吗? 谢谢!     
已邀请:
实际上,按以下方式更改代码应该可以工作。
ScriptManager.RegisterStartupScript(this.Page, typeof(System.Web.UI.Page), \"ShowEmailPreview\", \"alert(\'hi\');\", true);
    
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), \"ScriptName\", \"alert(\'hi\');\", true);
这是一个较短的版本     

要回复问题请先登录注册