I am using alert message using java-script to display some kind of warning when some conditions are not met. My only problem is when the alert message pops up and the users reads the message and clicks Ok, then it goes back to the original page but the page shifts to the left side. Normally my page shows in the center but only when the java-script runs then it shifts to the left side of the page. If i copy the same URL and paste in another page then everything will be aligned and will show in the center. How can i fix this? is there another alerting message like jquery or something else that works nice. Pls. help. thnaks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxControlToolkit;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web.Routing;
public partial class HomePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ID = Page.RouteData.Values["ID"] as string;
if (!IsPostBack)
{
BindData_Action();
}
}
protected void btnApproval_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT ID, Description, Target_Date FROM MyTable WHERE ID = '" + Request.QueryString["ID"] + "'", con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
//if the condition above is true i am sending an email
}
else
{
Response.Write("<script>alert('Before requesting Approval additional info. Thanks');</script>");
}
}
}
Using Response.Write can do some funky things to your styling. Instead of doing it in your C# code, break out the javascript separately.
One way to do it is to use RegisterStartUpScript in your C# – this tells the compiler to run this script after the page is loaded:
And then, right after your C# code section on your page ends, add this:
All this is doing is separating out the javascript that you had in your Response.Write.