JavaScript alert by C# code on asp.net web page by C#

JavaScript alert by C# code on asp.net web page by C# :

Redirect to a page/URL after alert button is pressed or implement javascript message in Code behind C#.

In this post we give a simple example to show javaScript alert message on asp.net web page by C#. Means we want to achive this by code behind page.

This is very simple some time we want to show some message on button click event or show when the condition is true or false . like that we consider a example we want to show a javaScript alert message by code if condition is true.

if (userTyle==”Admin”)
           {
               ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Notify", "alert('Notification : You are not user you are Admin .');” true);
           }

Redirect to a page after javascript alert has been dismissed in ASP.NET web page by C# code:


Some time we also want to display alert message and if javascript alert message dismissed then move to other web page.

if (userTyle==”Admin”)
           {
               ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Notify", "alert('Notification : You are not user you are Admin .');window.location.replace('Adminhome.aspx');", true);
           }

If you want to redirect after a purely client-side event, you need to do it in client-side code. Something like this:

window.location.replace('pageName.aspx');


Comments