2012-09-18 134 views
0

我有一個單選按鈕列表,當用戶選擇一個按鈕時,頁面重新加載並顯示正確的信息,但該按鈕已消失。如何在頁面刷新後選擇單選按鈕

有沒有辦法避免這種情況?

下面是HTML:

 <div class="checkBoxesColumn"> 
      <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="viewAll" value="0" runat="server" />View All</label> 
      <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="journey" value="1" runat="server" />My MBC Journey</label> 
      <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="challenges" value="2" runat="server" />Challenges</label> 
      <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="advice" value="3" runat="server" />Positive Outlooks &amp; Advice</label> 
      <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="thanks" value="4" runat="server" />Giving Thanks</label> 
      <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="perspective" value="5" runat="server" />Family/Friend Perspective</label> 
     </div> 

這裏是後臺代碼:

protected void Page_Load(object sender, EventArgs e) 
    { 
     // HIDE UNTIL 10/13 
     if (DateTime.Now > new DateTime(2012, 9, 12)) 
     { 
     mbcRadioList.Visible = true; 
     } 

    video myVideo = new video(); 

    string categoryID = "0"; 
    if (!string.IsNullOrEmpty(Request["category_id"])) categoryID = Request["category_id"]; 

    Hashtable ht = myVideo.ListingForWall(categoryID); 
    //Response.Write("Test: " + ht.Count); 
    //Response.Write("Test: " + ht["B-01"]); 

    StringBuilder myStringbuilder = new StringBuilder(); 

    for (int i = 1; i <= 36; i++) 
    { 
     string iStr = i.ToString(); 

     if (iStr.Length == 1) iStr = iStr.PadLeft(2, '0'); 

     //Response.Write("A-" + iStr + "<br />");    
     //Response.Write("TEST: " + ht["A-" + iStr] + "<br />"); 

     string videoClass = "videoWallThumb thumb" + iStr; 

     if (ht["A-" + iStr] != null) 
     { 
      string[] tmp = ht["A-" + iStr].ToString().Split('|'); 

      if (tmp[2] == "0") videoClass += " disabled "; 

      myStringbuilder.AppendLine("<a class=\"" + videoClass + "\" href=\"videoWallDetail.aspx?video_id=" + tmp[0] + "\"><img src=\"images/video_images/" + tmp[1] + "\" alt=\"\"/></a>"); 
     } 
     else 
     { 
      videoClass += " incomplete "; 
      myStringbuilder.AppendLine("<a class=\"" + videoClass + "\" href=\"#\"><img src=\"images/placeholder.jpg\" alt=\"\"/></a>"); 
     } 

    } 

    mosaicA.Text = myStringbuilder.ToString(); 
} 

如果我給的代碼不夠或混淆,請讓我知道,我想解決這個小問題,以便我可以繼續下一期。

在此先感謝!

回答

0

沒關係,我用了一個CATEGORY_ID開關的情況下...

switch ((Request["category_id"])) 
    { 
     case "0": viewAll.Checked = true; break; 
     case "1": journey.Checked = true; break; 
     case "2": challenges.Checked = true; break; 
     case "3": advice.Checked = true; break; 
     case "4": thanks.Checked = true; break; 
     case "5": perspective.Checked = true; break; 
    } 
1

當您選中複選框時,您是否嘗試過設置會話變量?這種方式在頁面重新加載,你可以看到哪一個被選中,並將其中一個設置爲true。

因此,您可以嘗試使用單選按鈕的Id設置會話變量,並在返回時讀取變量並設置該會話變量保持爲true的任何Id。

我不確定是否有更好的方法來解決這個問題,但這是首先想到的。

我可以建議的唯一的其他事情是,如果您要使用AJAX調用進行部分更新,那麼整個網頁不會重新加載。

相關問題