Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (dtcheck.Rows[0]["status"].ToString() == "1")
{
    Response.Redirect("AddEmployee.aspx");

}
else
{

    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "insert", "alert('Dear " + fpsPL.username + "  you dont have permission. ');", true);
    Response.Redirect("MasterHome.aspx");

}


when Respone.Redirect("MasterHome.aspx"); call,then Javascript message is not display..how can i show this javascript message?
Posted
Updated 3-Mar-14 21:57pm
v2
Comments
Tom Marvolo Riddle 4-Mar-14 3:59am    
Afaik it is not possible
Siva Hyderabad 4-Mar-14 4:01am    
what we do now?
Tom Marvolo Riddle 4-Mar-14 4:07am    
yes Ankur\m/ is right.I always do like this .it's the only way i know
Pranav-BiTwiser 4-Mar-14 12:28pm    
I didn't get your question...

This is a custom alert box, on clicking ok it will redirect to specified page.


C#
var dialogConfirmed = false;
function AlertRedirect(obj, title, dialogText, url) {

    if (!dialogConfirmed) {
        $('body').append(String.Format("<div id="dialog"><p>{1}</p></div>",
                    title, dialogText));

        $('#dialog').dialog
                ({
                    height: 100,
                    width: 200,
                    modal: true,
                    resizable: false,
                    draggable: false,
                    position: 'center',
                    closeOnEscape: true,
                    close: function (event, ui) { $('body').find('#dialog').remove(); },
                    buttons:
                    {
                        'OK': function () {
                            $(this).dialog('close');
                            dialogConfirmed = true;
                            location.href = url;
                        }
                    }
                });
    }
    return dialogConfirmed;
}



ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "startupScript", "AlertRedirect('','','Your Message Here.','" + url + "');", true);
 
Share this answer
 
Comments
Siva Hyderabad 4-Mar-14 7:51am    
+5
You are registering the client script block in the current page rather than MasterHome.aspx. That is why it doesn't display.
What you can do is pass a querystring in the URL. In your MasterHome.aspx page, check for the querystring. If it is there, register a start up client script (use RegisterStartupScript rather than RegisterClientScriptBlock) and it should work.
If you don't want querystring solution, you can store it in session, check it in that page, show message and clear the session.

Hope that helps!
 
Share this answer
 
try this..

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Hi", "alert('Alert Message');document.location.href='/Default.aspx';", true);
 
Share this answer
 
Create HelperCLass and add below code in that class

C#
public static void jsAlertAndRedirect(System.Web.UI.Page instance, string Message, string url)
       {
           instance.Response.Write(@"<script language='javascript'>alert('" + Message + "');document.location.href='" + url + "'; </script>");
       }




call this in C# as like
HelperClass.jsAlertAndRedirect(this, "Write your Message here", ResolveUrl("pageurl"));
 
Share this answer
 
Comments
Siva Hyderabad 4-Mar-14 7:51am    
thanks
sameer_dev 12-Mar-21 0:40am    
I have put this code but alert message is not shown.
Response.Write("alert('hello')");
 
Share this answer
 
You can apply the JavaScript in this manner:

Page.ClientScript.RegisterStartupScript(this.GetType(), "func", "window.top.location = ('WebForm1.aspx');", true);


Here I am changing the page location, you can show the alert box in palce of "Window.top.Location"

Also remember to apply jquery reference to your Application.
 
Share this answer
 
In controller declare an viewbag variable as fallows

C#
ViewBag.alertMessage = "Enter your message";


Place fallowing code in your view

JavaScript
@if (!string.IsNullOrEmpty(ViewBag.AlertMessage))
     {
      <script type="text/javascript">
          alert("@ViewBag.AlertMessage");
          ViewBag.AlertMessage = "";
      </script>
  }
 
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