2011-12-30 71 views
0

即時通訊使用c#在asp.net中進行測驗應用程序。以下代碼是我的開始頁面,點擊開始後我將重定向到我的問題頁面。 我添加了一個start.aspx頁面的唯一原因是...所以我可以初始化Session中的 值。 這裏在page_load事件中,request.QueryString [「testid」]總是導致null? 即我的條件是從來沒有真實的,每次我被重定向到我的「default.aspx」頁面。 是什麼原因?編寫測驗應用程序

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Collections; 

namespace TESTPROJ2 
{ 
    public partial class START : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      ArrayList a1 = new ArrayList(); 

      Session.Add("answerlist", a1); 
      Session.Add("quizid", 1); 

      if (Request.QueryString["testid"] != null) 
      { 
       int testID = int.Parse(Request.QueryString["testid"]); 
       Session.Add("quizid", testID); 
      } 
      else 
      { 
       Response.Redirect("DEFAULT.aspx"); 
      } 
     } 

     protected void startB_Click(object sender, EventArgs e) 
     { 
      Response.Redirect("QUEST.aspx"); 
     } 
    } 
} 
+0

你設置通過GET方法提交表單?該表單是否有名爲testid的輸入? – 2011-12-30 12:41:57

+1

對我來說看起來很好,你實際請求的完整URL(帶有查詢字符串)是什麼? – Arj 2011-12-30 12:42:09

+0

也可以嘗試測試if(Request.QueryString [「testid」] .length> 0)',它可能會返回一個空字符串。此外,請確保您的查詢字符串格式正確 – Arj 2011-12-30 12:43:45

回答

0

你好,如果你把它放到會話你不能看到它在查詢字符串,因爲你使用Response.Redirect不添加任何東西得到法(查詢字符串)


protected void startB_Click(object sender, EventArgs e) 
{ 
    int testId = 10; 
    Response.Redirect("QUEST.aspx?testid=" + testId); 
}