Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page.ClientScript.RegisterStartupScript not showing messages for 2nd time

Tags:

c#

alert

I'm using Page.ClientScript.RegisterStartupScript for displaying alert messages. it works fine for the first message, however second message wont display. Though it passes through the code while debugging.

Below is the code. Here only FiveDot File uploaded successfully message is displayed.

Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('FiveDot File uploaded successfully');", true);
Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('TwoDot File uploaded successfully');", true);

I've to show multiple alert messages in the webpage based on certain conditions.

like image 746
Interstellar Avatar asked Nov 15 '13 13:11

Interstellar


People also ask

What is the use of Page ClientScript RegisterStartupScript?

ClientScript. RegisterStartupScript for displaying alert messages. it works fine for the first message, however second message wont display. Though it passes through the code while debugging.

What is ScriptManager RegisterStartupScript in asp net?

RegisterStartupScript(Control, Type, String, String, Boolean) Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page.


1 Answers

Use different type or key to register second script as:

A client 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.

(taken from MSDN)

or just concatenate both script string.

Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('FiveDot File uploaded successfully'); alert('TwoDot File uploaded successfully');", true);
like image 117
gzaxx Avatar answered Sep 17 '22 06:09

gzaxx