页面加载事件执行两次

发布于 2025-02-13 10:38:08 字数 1550 浏览 0 评论 0原文

如果单击打开页面时,如果在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文