开发者

How do I set previously selected radio button checked in classic asp after page is postbacked?

I have never worked on classic ASP and unfortunately I am supposed to modify an old classic ASP web site.

ASP.Net ViewState does take care of maintaining control's state automatically. How do I do it in classic ASP?

I have two radio buttons and a text box placed on my ASP page. When the user types in something in the text box based on radio button selection we display different search results. No开发者_如何学编程w what I need is to keep the previously selected radio button as checked after the page is postbacked. How do I do that?


What I think people are expecting to find the answer to here is: How can I keep all radio buttons, checkboxes checked after postback (submit) ? Here is a simple answer:

<%
'keep radio buttons checked after postback (submit) in classic asp

if Request.Form("betaling") = "klarnaf" then
pCheckedKlarnaf = "checked=""checked"""
end if
if Request.Form("betaling") = "klarnak" then
pCheckedKlarnak = "checked=""checked"""
end if
if Request.Form("betaling") = "visa" then
pCheckedVisa = "checked=""checked"""
end if
if Request.Form("betaling") = "mastercard" then
pCheckedMastercard = "checked=""checked"""
end if
if Request.Form("betaling") = "postoppkrav" then
pCheckedOppkrav = "checked=""checked"""
end if
if Request.Form("frakt") = "servicepakke" then
pCheckedServicepakke = "checked=""checked"""
end if
if Request.Form("frakt") = "bedriftspakke" then
pCheckedBedriftspakke = "checked=""checked"""
end if
if Request.Form("frakt") = "kveld" then
pCheckedKveld = "checked=""checked"""
end if
%>

<input radio class="myclass" name="betaling" value="klarnaf" <%=pCheckedKlaraf%> />
<input radio class="myclass" name="betaling" value="klarak" <%=pCheckedKlanak%> />
<input radio class="myclass" name="betaling" value="visa" <%=pCheckedVisa%> />
<input radio class="myclass" name="betaling" value="mastercard" <%=pCheckedMastercard%> />
<input radio class="myclass" name="betaling" value="postoppkrav" <%=pCheckedOppkrav%> />


<input radio class="myclass" name="frakt" value="servicepakke" <%=pCheckedServicepakke%> />
<input radio class="myclass" name="frakt" value="bedriftspakke" <%=pCheckedBedriftspakke%>/>
<input radio class="myclass" name="frakt" value="kveld" <%=pCheckedKveld%> />


You use Request.Forms["rbcontrolname"] to retreieve the posted back value and then render out the radio button with same value it had before. There is no concept of server controls in classic asp, html controls have to be used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜