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

    How to cal alert message in server side.

    how to cal alert message in server side code.
    Im trying like this. Bt im getting error.
  • #677617
    Hi Phani
    You have not given anything at comma in your code.Just use the below code

    protected void Page_Load(object sender,eventargs e)

    string.Format("<script type='text/javascript'>alert("This is popUpMessage")</script>",true));

  • #677618
    Try this
    Page.ClientScript.RegisterStartupScript(typeof(Page), "myscript", "alert("message")", true);

  • #677624
    Add this in page load for a button click attribute

    btnAdd.Attributes.Add("onclick", "alert('Add');");

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #677625
    You have to check whether the radio button is clicked or not inside the onclick handler for the lnkbtnDownload.


    Thanks & Regards,
    Gaurav Agrawal

  • #677632
    try below code :

    ClientScriptManager cs = Page.ClientScript;
    Type ty = this.GetType();
    cs.RegisterStartupScript(ty, "key", "alert('your message');", true);

    If it helps you then Rate this.

    Best Regards,
    Manoranjan Sahoo

  • #677651
    Hi Phani,

    To call Javascript alert from Codebehind

    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Hi", "alert('This is popUpMessage');", true);


    CleintScript.RegisterStartupScript(this.GetType(),"key","<script type='text/javascript'>alert("This is popUpMessage")</script>")

    Hope this will help you

    Never lose hope..You never know what tomorrow will bring

  • #677652

    You can also define the alert in aspx file and call it from within code behind.

    See below example:

    <script language="javascript" type="text/javascript">
    function getCalledFromCodebehind() {
    alert("I got called from server side!");

    In code behind you can call the above function as:

    protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
    ClientScript.RegisterStartupScript(GetType(), "someKey", "getCalledFromCodebehind()", true);

    With the above code, the function is get called when page is first time loaded (!Page.IspostBack)

    Hope it'll help you.

  • #677708
    You can try like this

    System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Record Saved successfully!')</SCRIPT>");

    System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('IMO Number Already available!')</SCRIPT>");

    Thanks & Regards
    Nothing is mine ,Everything is yours!!!

  • #677756
    below code working fine.

    Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "alert('456');", true);

  • 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.