Skip to content

Alert message in C#

jazz right

Asked Apr 15, 2008, 4:17 PM EDT1 answer
Share
LinkedInX
i want to use the pop  box to appear when the user click the delete button asking the user 'Are you sure you want to delete'.
But the problem is when the user first hits the delete button the pop up message doesnt show up but when the delete button is clicked second time then the pop up message shows.
Can someone help me in this please. here is my code for reference:
protected void btnDelete_Click(object sender, EventArgs e)
        {
            btnDelete.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete')");
            lblMessage.Text = "Testing";
            lblMessage.Visible = true;
        }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Niradhip Chakraborty
    0

    Use the onclick attribute in page load.
    I mean to say inspite of using
     (btnDelete.Attributes.Add();)
    this  inside delete button event u can use it in page load.
    Your code will look like below:

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                 btnDelete.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete')");

            }

        }

    0