html - ASP.Net Display value for radio button selected on my confirmationpage -
i have 4pg asp.net
form storing data in session , button on 3rd page clears session. working fine i'm having 2 problems radio buttons.
first problem
on confirmation page (pg3) displaying 'true' or 'false'. want value 'yes' or 'no'. how do this
second problem
how display selected value on confirmation pg? know if needs wrapped in if
statement i'm unsure how write complete brain fart i'm afraid.
html page radio button on
<div class="form-group"> <div class="col-xs-12"> <asp:label id="label2" class="col-md-2 control-label" runat="server" text="do have kids?"></asp:label> <div class="col-md-3"> <asp:label runat="server" class="radio-inline"> <asp:radiobutton runat="server" id="pg2yes" value="yes" groupname="abc"/> yes </asp:label> <asp:label runat="server" class="radio-inline"> <asp:radiobutton runat="server" id="pg2no" value="no" groupname="abc"/> no </asp:label> </div>
code behind above
protected void pg2button_click(object sender, eventargs e) { session["pg2"] = txtdata2.text; session["pg2yes"] = pg2yes.checked; session["pg2no"] = pg2no.checked; response.redirect("/session/pg3.aspx"); } </div> </div>
confirmation page html
<% if (pg2yes == true) {%> <div class="form-group"> <div class="col-xs-12"> <asp:label id="label4" class="col-md-2 control-label" runat="server" text="kids?"></asp:label> <div class="col-md-3 form-control-static"> <%=session["pg2yes"] %> </div> </div> </div> <%} else {%> <div class="form-group"> <div class="col-xs-12"> <asp:label id="label5" class="col-md-2 control-label" runat="server" text="kids?"></asp:label> <div class="col-md-3 form-control-static"> <%=session["pg2no"] %> </div> </div> </div> <%} %>
it says if
statement following error:
the name 'pg2yes' not exist in current context
if declare variable
@ top, like:
<% var pg2yes == false; %>
i following error:
implicitly-types local variables must initialized
i'm new coding , not sure how this
first problem: change pg2button_click
to:
session["pg2yes"] = pg2yes.checked ? "yes" : "no"; session["pg2no"] = pg2no.checked ? "yes" : "no";
this way, store "yes" , "no" instead of boolean values "true" , "false"
second problem: try changing <% if (pg2yes == true) {%>
(this assuming change first problem):
<% if (session["pg2yes"] == "yes") {%>
Comments
Post a Comment