We use the confirm function to get the confirmation from the user.
Note : to prevent postback of a button click based on the
confirmation by the user, you need to return true/ false from the calling function
and from the calling event.
( OnClientClick="return getConfirm();"
)
Code Sample :
Design
<script
language="javascript">
function
getConfirm
{
return
confirm("Are
you sure want to get the server time?");
}
</script>
Page loaded at
Server Time :
<asp:Label ID="lblTime"
runat="server"></asp:Label>
<br
/>
<br />
<asp:Button ID="btnGetServerTime"
runat="server"
Text="Get Server Time"
OnClientClick="return getConfirm();"
OnClick="btnGetServerTime_Click"
/>
.CS Page
protected void
Page_Load(object sender,
EventArgs e)
{
if(!IsPostBack)
lblTime.Text
= DateTime.Now.ToString();
}
protected void
btnGetServerTime_Click(object sender,
EventArgs e)
{
lblTime.Text =
DateTime.Now.ToString();
}
O/p:
Once you click on the button it will ask yes/ no option. if you press yes option will execute the post back event of the button . if you press no button nothing will performed
Page loaded at
Server Time :
7/8/2014 3:55:48 AM
No comments:
Post a Comment