You must Sign In to post a response.
  • Category: ASP.NET

    How to display messagebox in same page?


    when i click submit button this "error" should display in same page in messagebox
    As for now,this messagebox displayin in blank page where it doesn't give proper
    look..can any1 giv me idea ?
  • #619391
    if You are using ajax then use below code :

    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append("alert('Error Occured...');");
    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "Key", sb.ToString(), true);

    If it helps you then Rate this.

    Best Regards,
    Manoranjan Sahoo

  • #619392

    Please see the following code may help you.

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

    public partial class _Default : System.Web.UI.Page
    localhost.Service1 svcc = new Service1();
    protected void Page_Load(object sender, EventArgs e)
    //string ss =svcc.HelloWorld();
    DisplayAlertMessage("Hello How r u ??");
    public void DisplayAlertMessage(string resMsg)
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append("<script type = 'text/javascript'>");
    Page.RegisterClientScriptBlock("MyMessage", sb.ToString());
    protected void btnCheck_Click(object sender, EventArgs e)
    DisplayAlertMessage("Hello How r u ??");

    Change it as per your requirement.


    Rajesh Kumar Parbat

  • #619404
    @rajesh kumar parbat

    this s my output for above coding..can u chek?

  • #619409
    If TextBox1.Text = "" Then
    displayalertmsg("Enter Items to search")

    End If
    Protected Sub displayalertmsg(ByVal sender As Object)
    Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()

    sb.Append("<script type = 'text/javascript'>")
    sb.Append("alert('Enter items to search')")

    ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), "key", sb.ToString(), True)
    End Sub

  • #619419

    string myStringVariable1 = string.Empty;
    myStringVariable1 = "Type any message."; ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable1 + "');", true);


  • #619426
    u can use Following Function Just Create alert.Cs file And Give Call to Function.....

    public static class Alert

    public static void Show(string message)

    string cleanMessage = message.Replace("'", "\\'");
    string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";

    Page page = HttpContext.Current.CurrentHandler as Page;

    if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
    page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);

  • #619439
    as Page not workin in VB

  • #619442
    this code is little fast..but still displayin in empty page..means in in background of messagebox only white page showin.

    ClientScript.RegisterClientScriptBlock(Me.GetType(), "Test", "<script language = 'javascript'> alert ('welcome'); </script>")

    I wan messagebox to display in same page of button "submit"
    I tried above given codes..not effective

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.