Xybernetics ASP.NET C# - Messagebox for debuggingThis tech tip is gonna be a really short one and it is pertaining to popup message box.
Sometime we really want to popup a message for the purpose of debugging and tracing the code or simply to… you know popup some message box for no apparent reason. Whatever you reason be, this is the way to get a popup in ASP.NET in C# framework.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class RabiWasHere : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Hello Claire');</script>");
    }
}


Output

This is what you will get when you load your ASP.NET webpage.

Xybernetics ASP.NET C# - Messagebox for debugging

Concatenate variables to the alert to output variable values (for debugging)… just make sure you follow JavaScript and or C# syntax.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class RabiWasHere : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    	string strHowAreYou = ", how are you doing?";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Hello Claire '" + strHowAreYou + ");</script>");
    }
}