RegisterStartupScript on page launch - 如何做到这一点?

RegisterStartupScript on page launch - How can this be done?

我很抱歉这个看起来很初级的问题,但在 C# 中还有很多东西需要学习!

我试图在特定条件下加载页面时弹出消息。

我有我的 If/Else 如果所有设置都正常,现在我需要在满足某些条件时添加弹出消息。

我的问题是,我只用过这样的东西:

ScriptManager.RegisterStartupScript(btnSubmitWork, typeof(Button), "Data Entry", 
"alert('Please note that you are in the UAT link')", true);

但是,这次不会涉及任何按钮,我希望它在页面加载时弹出。

如何实现?

不要使用按钮,而是使用 PageGetType() 作为前两个参数:

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Data Entry", 
"alert('Please note that you are in the UAT link');", true);

通过结合 hutchonoid 的答案和发布在 link 上的已接受答案,我能够使用以下方法让它工作:

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Data Entry", 
"alert('Please note that you are in the UAT link');", true);

只有两个微小的差异;使用 "Page.GetType()" 而不是仅 "GetType()",并在警报消息末尾使用分号。我会给 hutchonoid 支票,因为他把我带到了那里。