Reputation: 447
I have a list of radio buttons and when the user selects a button, the page reloads and the correct information appears, but the button is gone.
Is there a way to avoid this?
Here is the 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 & 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>
And here is the code-behind:
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();
}
If the code I gave is not enough or confusing please let me know, I am trying to get this minor issue resolved so I can move on to the next issue.
Thanks in advance!
Upvotes: 0
Views: 1536
Reputation: 447
Never mind, I used a switch case on the 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;
}
Upvotes: 0
Reputation: 4681
I think that is a ViewState issue. Only web controls has the viewstate maintained, what keeps the information between postbacks.
Check this: Which controls have ViewState maintained?
Upvotes: 2
Reputation: 343
Have you tried setting a session variable when the check box is selected? This way on page reload you can see which one is selected and set that one to true.
So you can try setting a session variable with the Id of the radio button, and when it returns and you read the variable and set whichever Id that session variable is holding to true.
I'm not sure if there are better ways of going about this, but it's the first thing that came to mind.
The only other thing I could suggest is if you were to do a partial update using an AJAX call so the entire webpage doesn't reload.
Upvotes: 1