Click here to Skip to main content
Rate this: bad
good
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 21:08pm
Edited 1-Feb-12 0:52am
v2
Comments
Vani Kulkarni at 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 at 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 at 10-Jul-12 2:17am
   
Good answer! 5!
Rahul Rajat Singh at 10-Jul-12 2:22am
   
thanks.
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 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
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 15

alert: ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "alertMessage", "alert('The shopping cart is empty. Login may have to login to see your items.')", True)
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 16

alert & Redirect:ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "ScriptKey", "alert('The shopping cart is empty. Login may have to login to see your items.');window.location='Login.aspx'; ", True)
  Permalink  
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 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>";
        Response.Write(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 at 14-May-12 4:46am
   
how to change the Title of this alert windows/message box???

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

  Print Answers RSS
0 OriginalGriff 483
1 Sergey Alexandrovich Kryukov 207
2 RyanDev 165
3 PhilLenoir 160
4 RajeeshMenoth 110
0 Sergey Alexandrovich Kryukov 6,415
1 OriginalGriff 5,856
2 CPallini 2,473
3 Richard MacCutchan 1,667
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 22 Aug 2014
Copyright © CodeProject, 1999-2014
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