Hi,
I am having a problem trying to pop up a confirm message box in the client side when a condition is met in the server.
I have a delete button that when pressed, could warm the user of something if that condition evaluates true in the server side.
I can get the confirm message box to appear if I add attributes to my delete button on my form_Load event:
something like this:
protected void Page_Load(object sender, EventArgs e)
{
btnDelete.Attributes.Add("OnClientClick","return confirm( 'You are going to Delete everything. Are you sure?'");
}
but this just guarantee that the message will pop up everytime I pressed the delete button and not just when the condition is met.
I also tried to register a script in my btnDelete_Click event, doing something like this:
protected void btnDelete_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"<script language='javascript'>");
sb.Append(@"return confirm('Delete Everything?');");
sb.Append(@"</script>");
if (!ClientScript.IsStartupScriptRegistered("JSScript"))
{
ClientScript.RegisterStartupScript(typeof(Page), "JSScript", sb.ToString());
}
}
but in this case the message box just appear when I click the button twice.
Can anybody help me with this? I would really appreciate any ideas.
Thanks,
Al
I am having a problem trying to pop up a confirm message box in the client side when a condition is met in the server.
I have a delete button that when pressed, could warm the user of something if that condition evaluates true in the server side.
I can get the confirm message box to appear if I add attributes to my delete button on my form_Load event:
something like this:
protected void Page_Load(object sender, EventArgs e)
{
btnDelete.Attributes.Add("OnClientClick","return confirm( 'You are going to Delete everything. Are you sure?'");
}
but this just guarantee that the message will pop up everytime I pressed the delete button and not just when the condition is met.
I also tried to register a script in my btnDelete_Click event, doing something like this:
protected void btnDelete_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"<script language='javascript'>");
sb.Append(@"return confirm('Delete Everything?');");
sb.Append(@"</script>");
if (!ClientScript.IsStartupScriptRegistered("JSScript"))
{
ClientScript.RegisterStartupScript(typeof(Page), "JSScript", sb.ToString());
}
}
but in this case the message box just appear when I click the button twice.
Can anybody help me with this? I would really appreciate any ideas.
Thanks,
Al