如何在asp.net中使用会话查询字符串 [英] How to use query string with session in asp.net

查看:68
本文介绍了如何在asp.net中使用会话查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello 
How to use query string with session  in asp.net
I am working on a website containing a form which must be filled by the users. In the first page, the users by clicking the register button is referred to the second page where the user will be required to complete the registration process. 
Now my question is that how can I make it possible that when a user submits the register button in the first page must be the same user in the second page, means that the same user must be displayed in the dropdown list of the second page which is done by query string? 
As an example, below are codes which may help you better understand my question  
  
Page 1

  try
            {

                con.Open();
                cmdin.ExecuteNonQuery();
                cmdin.Parameters.Clear();
                LabelSuccsessful.Visible = true;
                LabelSuccsessful.Text = "Registration was sucessfully";
              
             
                //Session["Person_TB"] = TextBox_PersonName;
                //Response.Redirect("~/EducationPersons.aspx?pid="+XXXXXX);
                
            }
            catch
            {
                LabelSuccsessful.Visible = true;
                LabelSuccsessful.Text = "Registration was failed try again";

            }
            finally
            {
                con.Close();
                con.Dispose();
            }//----------------------------------

Page 2 
       
        //---------------show the name of user
        string strcmd = "Select Person_Name from  Person_TB where Person_ID=@piid";
        SqlCommand cmd = new SqlCommand(strcmd, con);
        cmd.Parameters.Clear();
        con.Open();
        //cmd.Parameters.AddWithValue("@iid", Request.QueryString["pid"]);
        SqlDataReader dr;
        dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            LabelpersWelcom.Text = "Welcome Dear";
            LabelWEduPerson.Text = dr["Person_Name"].ToString();
           // DropDownListPersonName.SelectedValue = dr["Person_Name"].ToString();

        }
        con.Close();//----
       
    }//-------end of PageLoad

推荐答案

在第1页上创建会话变量。

检查页面上的会话值Page 2

Create Session Variable on Page 1.
Check Session Value on Page Load of Page 2
if(Session["Person_TB"] == null)
    // Redirect To Error Page





在将名称分配给标签之前检查会话值。 />



check Session Value Before Assign Name to Label.

// user can change Query String Value
if(dr["Person_Name"].ToString() == Session["Person_TB"].ToString())
  // LabelWEduPerson.Text = dr["Person_Name"].ToString();
else
 // Redirect To Error Page


试试这个

ASP.NET 2.0向导控制 [ ^ ]


这篇关于如何在asp.net中使用会话查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆