www.webdeveloper.com
Results 1 to 3 of 3

Thread: Writing Javascript from CodeBehind

  1. #1
    Join Date
    Apr 2011
    Posts
    2

    Unhappy Writing Javascript from CodeBehind

    Hello:

    I have a JS script which I wrote in my code behind. This is not giving me any err or anything but it is not showing me an alert mesg. I am using Visual Studio 2010 with 4.0 framework. Here is my code:

    Code:
    MessageBox1("Testing my Message"); //Calling Function!
    
     private void MessageBox1(string msg) //This is in the code behind of the page.
        {
    
    
            // Cleans the message to allow single quotation marks
            string cleanMessage = msg.Replace("'", "\\'");
            string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";
    
            // Gets the executing web page
            Page page = HttpContext.Current.CurrentHandler as Page;
    
            // Checks if the handler is a Page and that the script isn't allready on the Page
            if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
            {
                page.ClientScript.RegisterClientScriptBlock(typeof(CommSetup), "alert", script);
            }
    
    
        }
    Why it is not showing any alert box?

  2. #2
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    you'll probably want someone in the asp.net forums look at it first

  3. #3
    Join Date
    Apr 2011
    Posts
    2
    Okay! Thanks...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles