Show (Display) JavaScript Alert Message box in middle of screen from code behind in ASP.Net

prawinrajkumar3
 
on Jul 21, 2021 07:37 AM
791 Views

Show (Display) JavaScript Alert Message box in middle of screen from code behind in ASP.Net

The pop-up is on top center of the page, please suggest for middle of the page.

protected void Page_Load(object sender, EventArgs e)
{
    string message = "Hello! Mudassar.";
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append("<script type = 'text/javascript'>");
    sb.Append("window.onload=function(){");
    sb.Append("alert('");
    sb.Append(message);
    sb.Append("')};");
    sb.Append("</script>");
    ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jul 21, 2021 07:41 AM

Hi prawinrajkuma...,

This is browser inbuilt functionality and it is different in each brower. You can't change it.

If you wan to display center of page use jquery or bootstrap modal popup to display the message.

Refer below articles.

Open (Show) Bootstrap Modal Popup Window from Server Side (Code Behind) in ASP.Net

Open ( Show ) jQuery UI Dialog Popup Window from Server Side ( Code Behind ) in ASP.Net

prawinrajkumar3
 
on Jul 22, 2021 04:42 AM

Thank sir, is there any other way to show alert popup in center of the page without using jquery & bootstrap.

or  we can make this popup customize to center.

 

protected void Page_Load(object sender, EventArgs e)
{
    string message = "Hello! ";
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append("<script type = 'text/javascript'>");
    sb.Append("window.onload=function(){");
    sb.Append("alert('");
    sb.Append(message);
    sb.Append("')};");
    sb.Append("</script>");
    ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());

 

dharmendr
 
on Jul 22, 2021 04:44 AM

No, its not possible.