I want to create a Javascript alert in an asp.net web application. But i can’t able to create this. I post my partial code is here the script manager javascript alert not displayed. Please help me to show the javascript alert..
if (noofday > totalday)
{
// I want to display the confirm message box in this section
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "return confirm('Are you sure you want to delete');", true);
if(true)
{
DataSet5TableAdapters.sp_inleaverequestTableAdapter TA = new DataSet5TableAdapters.sp_inleaverequestTableAdapter();
TA.GetData(lbl_empcode.Text, lbl_empname.Text, lbl_dept.Text, txtfromdate.Text, txttodate.Text, Convert.ToString(noofday), ddlleavetype.SelectedItem.Text, Convert.ToString(totalday), txtreason.Text, ddlforward.SelectedItem.Text, " ", " ", " ", " ", lbl_date.Text);
Send_Email(lbl_empcode.Text, lbl_empname.Text, txtfromdate.Text, txttodate.Text, noofday, ddlleavetype.SelectedItem.Text, txtreason.Text);
clear();
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "<script language='javascript'>alert('Request sent successfully. Go and watch your status..');</script>", false);
}
else
{
//DO Something
}
}
else
{
DataSet5TableAdapters.sp_inleaverequestTableAdapter TA = new DataSet5TableAdapters.sp_inleaverequestTableAdapter();
TA.GetData(lbl_empcode.Text, lbl_empname.Text, lbl_dept.Text, txtfromdate.Text, txttodate.Text, Convert.ToString(noofday), ddlleavetype.SelectedItem.Text, Convert.ToString(totalday), txtreason.Text, ddlforward.SelectedItem.Text, " ", " ", " ", " ", lbl_date.Text);
Send_Email(lbl_empcode.Text, lbl_empname.Text, txtfromdate.Text, txttodate.Text, noofday, ddlleavetype.SelectedItem.Text, txtreason.Text);
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "<script language='javascript'>alert('Request sent successfully. Go and watch your status..');</script>", false);
clear();
}
I would suggest that you first try to figure out if the code you expect is being returned to the page.
There are few ways to do this, with the easiest being “View Source” on the page after your above code runs. If you can find that content in the page, you will know that the content is being returned to the page but not executed.
If you do not see the content when viewing source, then you have a different problem. Either control is being passed to another page, or its not actually going to the if condition you expect.
Once you understand where the problem originates from these two pieces, you can start to find what may be causing it.
It is also somewhat apparent that you may not completely understand how the web works. Given this set of code….
… it appears that you are expecting the page execution on the server to stop and then wait for the client to respond. This is not how the web page life cycle works. The server code is going to execute completely and send content back to the client. Its not an interactive process (even with AJAX) like a windows forms or console application.