0

I am doing project in asp.net in C#. I am trying to show message in script format. For that i am using the below code

Page page = new Page();
page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Key", "alert('Your Full Name Sucessfully Updated...');", true);

but it is not showing any error. or warning. even it is not showing the messege. kindly suggest me and help me.

Thanks and Regards

4 Answers 4

1

The reason it doesn't show up your message is that you're only registering your script; you have to call it from the client side.

Furthermore, don't create a new Page instance as suggested by others.

You can modify your <body /> tag to call showMsg() using the OnLoad property

<body onload="showMsg()">

Worths a try!

EDIT: And add your javascript code as follows:

 ClientScript.RegisterStartupScript(this.GetType(), "showMsg", "alert('boo ya!');");
Sign up to request clarification or add additional context in comments.

1 Comment

Thnx for ur reply. But I have already define a function in Onload and I have to define it inside the button click. After the Fullname Updated.
0

You need to use the existing page within a page:

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Key", "alert('Your Full Name Sucessfully Updated...');", true);

should do it.

2 Comments

Thanx for ur responce. Yes, I have also try this one. But this one is also behaving the same no respond.
Then check if the js is in the page source. If not, consider where in the page lifecycle you are adding it. ( as per @slavo )
0

You are creating a new instance of the page object and registering the script with this new instance. Instead, you should register it with the current page that is executing.

this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Key", "alert('Your Full Name Sucessfully Updated...');", true);

Notice there is no new keyword.

Also, I think this should be done on the Init event of the lifecycle and not later.

2 Comments

Thnx for your reply. I have tried this one, but it is also not working.
Are you getting any Javascript errors when the page runs? You can check in a tool like Firebug and also see if the script has been loaded at all.
0

The new Page() looks wrong. Seems to me you'll want this.Page.ClientScript.RegisterClie... instead somewhere.

The first test is, when you get the page from the server, does it contain any javascript? Then, get the script to work right if it doesn't.

2 Comments

Thanx friend. But i have already tried this method it is also not working.
Ok. What isn't working about it? Does the javascript not get into the html output received by the browser? It most definitely needs to be this.Page... (or just Page...) rather than new Page().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.