2015-03-31 16 views
1

我有兩頁,我將會話ID傳遞給兩頁。它工作正常,但在Form1中,我想同時打開form2和form3。應該是什麼條件才能打開這兩種表格?如何通過多個頁面的會話ID?

string name = GridView1.SelectedRow.Cells[2].Text + ' ' + GridView1.SelectedRow.Cells[3].Text; 
    Session.Add("First_Name", name); 
Response.Redirect("General_Bill.aspx?First_Name=" + this.lblname.Text); 
Response.Redirect("Add_admission_record.aspx?First_Name=" + this.lblindex.Text); 

上面的代碼只是打開form2.aspx而不是form3。請相應地指導我。

+0

是否要同時打開兩個頁面? :O – Peyman 2015-03-31 05:11:23

+0

第一個Redirect會終止您的方法執行,所以第二個不會運行。 – treaschf 2015-03-31 05:13:01

+0

不,當我點擊Add_admission_record那個形式時,一個圖像按鈕在那裏,那個imgae按鈕我給上面的形式link.i表示當前一頁是Add_admission_record,然後打開Add_admission_record,否則打開General_Bill。 – 2015-03-31 05:13:39

回答

2

使用此代碼並傳遞id多個頁面。

<asp:TemplateField HeaderText="ACTION"> 
     <ItemTemplate> 
    <%-- <asp:LinkButton ID="id" runat="server" OnClientClick="ram(<%#Eval("id")%>"></asp:LinkButton>--%> 

    <a href ='<%#"ViewAddmissionform.aspx?id="+DataBinder.Eval(Container.DataItem,"id") %>'> View </a>/ 
    <a href ='<%#"EditAddmissionform.aspx?id="+DataBinder.Eval(Container.DataItem,"id") %>'>Edit </a>/ 
    <a href ='<%#"Student Report.aspx?id="+DataBinder.Eval(Container.DataItem,"id") %>'>Attendance </a>/ 
     <a href ='<%#"PrintRegisrationForm.aspx?id="+DataBinder.Eval(Container.DataItem,"id") %>'>Print </a> 

     </ItemTemplate> 
     </asp:TemplateField> 
0

試試這個

string name = GridView1.SelectedRow.Cells[2].Text + ' ' + GridView1.SelectedRow.Cells[3].Text; 
Session.Add("First_Name", name); 
string pageName = Session["First_Name"].ToString(); 
    if(pageName.ToUpper()=="GENERAL_BILL.ASPX") 
     Response.Redirect("General_Bill.aspx?First_Name=" + this.lblname.Text); 
    else 
     Response.Redirect("Add_admission_record.aspx?First_Name=" + this.lblindex.Text); 
+0

好吧,我會嘗試這個..thanxs重播.. :-) – 2015-03-31 05:25:27

+0

它給出錯誤'對象引用未設置爲對象的實例。' – 2015-03-31 05:28:46

+0

會話的名稱是什麼? – Mairaj 2015-03-31 05:32:09

0

在你的代碼中創建一個會話變量後面(我假設您使用的WebForms工作)。

Session["Name"] = name; 

而不是讓下頁這個Session變量的訪問可以使用下面的代碼獲得它:

HttpContext.Current.Session["Name"].ToString(); 

所以第2頁或第3頁

您可以聲明像這樣的新變量:

string valueFromPageOne = HttpContext.Current.Session["Name"].ToString(); 
相關問題