Click here to Skip to main content
12,079,391 members (30,617 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# .NET
Hi

I used the following code to display alert message but i am not getting any thing Please check this
string strMsg = "Leave has been applied already between " + txtFromDate.Text.Trim() + " and " + txtToDate.Text.Trim() + "";
                        string script = "<script language="\""javascript\" type=\"text/javascript\">alert('" + strMsg + "');</script>";
                        Response.Write(script);
Posted 31-Jan-12 22:08pm
Edited 1-Feb-12 1:52am
v2
Comments
Vani Kulkarni 10-Jul-12 2:18am
   
Shashwath, I suppose you have received many solutions, please mark them as answers and close this question.
Rahul Rajat Singh 10-Jul-12 5:33am
   
I agree with Vani.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Sort out your double quotes:
string script = "<script language="\""javascript\"
Becomes
string script = "<script language=\"javascript\"
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 9

i hope, it will work

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
 ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Data Insert Successfully...');", true);
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 10

although all the answers given here are correct, you might find this article interesting.

this gives you a reusable class to do the same thing.

A Windows Form like MessageBox for ASP.NET Website[^]
  Permalink  
Comments
Vani Kulkarni 10-Jul-12 2:17am
   
Good answer! 5!
Rahul Rajat Singh 10-Jul-12 2:22am
   
thanks.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

check This .

Page.RegisterStartupScript("Key", "<script type='text/javascript'>window.onload = function(){alert('Please accept Terms and Conditions before submitting.');return false;}</script>");
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

string strMsg = "Leave has been applied already between " + txtFromDate.Text.Trim() + " and " + txtToDate.Text.Trim() + "";
        string script = "<script language="\"javascript\"" type="\"text/javascript\"">alert('" + strMsg + "');</script>
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

modify as

string strMsg = "Leave has been applied already between " + txtFromDate.Text.Trim() + " and " + txtToDate.Text.Trim() + "";
                     string script = "<script language="\""javascript\" type=\"text/javascript\">alert('" + strMsg + "');</script>";
                     Response.Write(script);

Note: Try to show alert message from javascript without postback
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

As OriginalGriff suggested you have missed out the string formatting. Below is working.

txtFromDate.Text = DateTime.Now.AddDays(-2).ToString("MM/dd/yyyy");
            txtToDate.Text = DateTime.Now.AddDays(2).ToString("MM/dd/yyyy");
            string strMsg = "Leave has been applied already between " + txtFromDate.Text.Trim() + " and " + txtToDate.Text.Trim() + "";
            string script = "<script language="\""javascript\" type=\"text/javascript\">alert('" + strMsg + "');</script>";
            Response.Write(script);
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('user created')</script>");


Hope this may help you..
  Permalink  
Comments
Mithun Patra 14-May-12 4:46am
   
how to change the Title of this alert windows/message box???
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 14

ss="100";
ss = ss.Insert(0, "Succesfully added the voucher entry! Voucher No ");
 
             ScriptManager.RegisterStartupScript(this, this.GetType(), "", "<script>alert('" + ss.ToString() + "');</script>", false);


Hope this may help you..
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 8

string strMsg = "Leave has been applied already between " + txtFromDate.Text.Trim() + " and " + txtToDate.Text.Trim() + "";
Response.Write("<script>alert('"+strMsg +"')</script>");

Hope this may help you..
  Permalink  
v2
Comments
Member 12017661 28-Sep-15 14:00pm
   
Response.Write("<script>alert('"+strMsg +"')</script>");

this works perfect for displaying an output result in alert box.

Thanks.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 11

To make your web application efficient you can add one class named MessageBox in your AppCode folder.
please cheak this link

www.codeproject.com/KB/webforms/AspNetMsgBox.aspx[^]
Sorry to say but before posting questions you must check the prev posts as there are many posts asking same question
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 12

string strMsg = "Leave has been applied already between " + txtFromDate.Text.Trim() + " and " + txtToDate.Text.Trim() + "";
                        string script = "<script language="\""javascript\" type=\"text/javascript\">alert('" + strMsg + "');</script>";
                        Response.Write(script);

problem in wrong used of "" please sort out it.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 13

string strMsg = "Leave has been applied already between " + txtFromDate.Text.Trim() + " and " + txtToDate.Text.Trim() + "";
                        string script = "<script language="\""javascript\" type=\"text/javascript\">alert('" + strMsg + "');</script>";
                        Response.Write(script);

problem in wrong used of "" please sort out it. and either you can used messageBox to display your message in alert .
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 17

ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Write Your Message');", true);
  Permalink  
Comments
RyanDev 20-Mar-15 10:13am
   
Please do not answer questions that are very old and are very answered already. Your account will get flagged as abusive and closed. You did not add any value to this question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160212.1 | Last Updated 28 Aug 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100