Donate

ScriptManager.RegisterStartupScript() Vs. ClientScript.RegisterStartupScript()

Hi!

I have been struggling in manipulating scripts to focus to a particular control when a user executes a button or events triggered by postbacks.The scenario was in every button clicked, the focus will be transferred to another control. These butttons are inside an update panel and ajax tab container. The solution presented in an article i've previously posted was using ClientScript.RegisterStartupScript() to register a script. However, this script is registered in the Page object. But since my controls are inside an update panel which is partial postback rendering, the solution I've come up was using ScriptManager.RegisterStartupScript(). So, to register client scripts on an aspx page w/o ajax functionalities, use ClientScript:
1
ClientScript.RegisterStartupScript(this.GetType(), "MyScript", script.ToString(), false);  

And to register client scripts on an aspx page w/ ajax functionalities such as inside an update panel, use ScriptManager:
1
ScriptManager.RegisterStartupScript(this, this.GetType(), "MyScript", script.ToString(), false);  

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations