Reputation: 1245
I have 2 user control placed on web page, in user_control_load event i am adding some client side script.
so when user control 1 page load is fired, it adds a script. when page 2 load function is called it again writes the script with same key but in source view of the page i am seeing the script added by user control 1. i was expecting user control 2 should overwrite the script because key is same but its not happening, any idea how can i overwrite the script with same key.
Upvotes: 0
Views: 623
Reputation: 1450
As per MSDN a startup script is uniquely identified by its key and its type. Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page. Attempting to register a script that is already registered does not create a duplicate of the script.
Me.Page.ClientScript.RegisterStartupScript(Me.GetType, "aa", "alert('first');", True)
Me.Page.ClientScript.RegisterStartupScript(Me.GetType, "aa", "alert('second');", True)
In above code example only the first script will got registered, second will not. For more details please follow the documentation.
Upvotes: 1
Reputation: 6446
I think its not possible to overwrite the script added with the same key. Since both usercontrols are used in the same page what is the use of adding script in one control load, then again rewriting in the second control load. Instead just add the the script in the second control load.
Upvotes: 0