页面加载事件执行两次
如果单击打开页面时,如果在Word文件中具有此链接。 http:// localhost:54818/upervelinks/uperve.aspx?upersid = 80
,在页面加载中,我写了此代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// GET THE ID OF THE OFFER
string id = Request.QueryString["Offerid"];
// GET THE LINK AND THE LINK COUNT
if (id != null)
{
string linkName = "";
string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("SpOfferbyId", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramid = new SqlParameter("@ID", Convert.ToInt32(id));
cmd.Parameters.Add(paramid);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
linkName = rdr["Link"].ToString();
}
Response.Redirect(linkName,false);
id = string.Empty;
}
}//end if
}
当我进行调试时,我发现查询字符串读取了参数并执行了代码 1-执行页面内容的页面加载 2-执行主页的页面加载 3- ec = xecute 内容页面的页面载荷再次
ps:没有什么页面
if have this link in word file when click it open the page offers.aspx
http://localhost:54818/offerslinks/offers.aspx?Offerid=80
and in the page load I wrote this code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// GET THE ID OF THE OFFER
string id = Request.QueryString["Offerid"];
// GET THE LINK AND THE LINK COUNT
if (id != null)
{
string linkName = "";
string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("SpOfferbyId", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramid = new SqlParameter("@ID", Convert.ToInt32(id));
cmd.Parameters.Add(paramid);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
linkName = rdr["Link"].ToString();
}
Response.Redirect(linkName,false);
id = string.Empty;
}
}//end if
}
when I made debugging I found the query string read the parameter and execute the code
1- execute the page-load of page content
2- execute the page-load of the master page
3- ec=xecute the page-load of the content page again
ps: there is no anything the page
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论