Page.ClientScript with master page

In VS2005 ASP.NET 2.0 sqlserver 2000:
I use the following function to show error messages in my site:

public void ShowMessage(string keymsg)
    {
      string myScript = @"alert('this is my message)";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", myScript, true);
    }
but when I use it in a slave of a master page, it gives an error.
Do I have to define it in the master page ? and how to call it?
Thankyou
Ant
   
ANAT2403Asked:
Who is Participating?
 
Jojo1771Commented:
aki4u is correct..  

Hey SuperGhosty.

You are correct that you need the script tags, but  the last boolean on startupscript; when set to true will gen that for you.


This should work
string myScript = @"alert('this is my message;);";

I just tested it in a master page and it works great.

If this worked, please give pnts to aki4u as he mentioned it 1st. Im just bored and thought I would comment on the issue.
0
 
SuperGhostyCommented:
public void ShowMessage(string keymsg)
    {
      string myScript = @"<script language='javascript'>alert('this is my message)</script>";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", myScript, true);
    }
0
 
aki4uCommented:
>> 'this is my message << needs to be: 'this is my message'
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
SuperGhostyCommented:
thats right, i just quickly glanced at the code and was used to ASP.NET 1.1 - which does not have the extra params so you must include the script tag.
0
 
ANAT2403Author Commented:
Jojo1771 is almost correct
this is the solution:
  string myScript = @"alert('this is a message');";

the second tag ' in    - this is a message I forgot to put here but in my program it existed.
the problem was with the ; sign that I didn't know I have to add
Thankyou all.
0
 
aki4uCommented:
hmmm...I don't see any points here
0
 
ANAT2403Author Commented:
because you didn't mention the sign of semicolon ; which was the only problem here.
The closing tag you mention was something I forgot to write in expert exchange but not in the program
0
 
aki4uCommented:
don't you use copy-paste???
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.