getting value from confirm message box

Posted by Shoyebaziz123 under Regular Expressions on 6/23/2011 | Points: 10 | Views : 5069 | Status : [Member] | Replies : 1
Hi,

i have written this code for javascript
<script type="text/Javascript" language ="javascript" >

function SomeFunction(ctl)
{
if (confirm("Are you sure?"))
{
document.getElementById(ctl).value = "Ok";
return true;
}
else
{
document.getElementById(ctl).value = "Cancel";
return true;
}
}

</script>

protected void Page_Load(object sender, EventArgs e)
{

btnDelete.Attributes.Add("OnClientClick", "return SomeFunction('" + HiddenResult.ClientID + "')");
}

protected void btnDelete_Click(object sender, EventArgs e)
{
if (HiddenResult.Value == "OK")
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "test", "alert('put code here')", true);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "test", "alert('Do Nothing')", true);
}

HiddenResult.Value = "";
}
but it still not working ... showing alert Do Nothing... means hidden field value not set.




Responses

Posted by: Jpchoudhari on: 6/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

try this

<asp:Button ID="btnDelete" OnClientClick="javascript:return confirm('Are you sure??')"
runat="server" Text="Button" OnClick="btnDelete_Click" />

Server side click event "btnDelete_Click" will execute only after user press OK.

Thanks and Regards,
Jaydeep Choudhari

Kind Regards,
Jay

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response