Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have to show a message-box when the data gets stored.
I have used this code...

It worked fine when i tested it with demo website...But when i applied it in my web-application, it showed me no error but also the message-box didn't popup.

C#
protected void btnok_Click(object sender, EventArgs e)
      {
          try
          {
              string _status = "Pending";
              //bool _result = _objVreg.insertdata(_strTablename, txtname.Text.ToString(), txtmobileno.Text.ToString(), txtcompany.Text.ToString(), txtpurpose.Text.ToString(), ddldepartment.SelectedItem.ToString(), ddlcontacperson.SelectedItem.ToString(), txtcity.Text.ToString(), System.DateTime.Now, Session["UserName"].ToString(), "", _status);
              bool _result = _objVreg.insertdata(_strTablename, txtname.Text.ToString(), txtmobileno.Text.ToString(), txtcompany.Text.ToString(), txtpurpose.Text.ToString(), ddlbranch.SelectedValue.ToString(), ddldepartment.SelectedValue.ToString(), ddlcontacperson.SelectedValue.ToString(), txtcity.Text.ToString(), System.DateTime.Now, "", "", _status, txtluggage.Text.Trim());
              if (_result == true)
              {
                  Alert.Show("Record Added Successfully");

              }
              else
              {
                  lblMsg.Text = "Record Not Added, Please Try Again";
              }
          }
          catch (Exception ex)
          {
              Response.Write(ex.Message);
          }
      }


I have added a class named "Alert.cs" which shows any popup passed as string.
The class is

C#
public static class Alert
   {

       /// <summary>
       /// Shows a client-side JavaScript alert in the browser.
       /// </summary>
       /// <param name="message">The message to appear in the alert.</param>
       public static void Show(string message)
       {
           // Cleans the message to allow single quotation marks
           string cleanMessage = message.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 already on the Page
           if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
           {
               page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
           }
       }

   }


Please guide me...

UPDATE:
OP resolved it by himself and posted it as one of the answer.
Posted
Updated 7-May-11 8:28am
v3
Comments
thatraja 7-May-11 11:47am    
Check if any error in firefox error console , include that in your question if you catch any.

 
Share this answer
 
Comments
ashu2188 7-May-11 12:04pm    
i have already tried that second link and added the class...it works fine with the website but not for web application
Its solved...i guess i was getting the problem because the page was getting post back ..
I simply redirected the page after save and passed a querystring value to it..and checked it at load the querystring value...

and put the popup at load of the redirected page..it worked fine there...
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900