Solved

asp.net read html controls

Posted on 2013-01-24
3
399 Views
Last Modified: 2013-02-09
I have the following codes to read radio button, but it does not show any values.
Any ideas what's wrong?

protected void SendMeQuote_Click(object sender, EventArgs e)
        {
            var x = Request.Form["radio"];
            Msg.Text = "Show: " + x;
        }            
                                <asp:Label runat="server" ID="Msg"></asp:Label>
                         <div class="f-item">
                              <input type="radio" name="radio" id="flight" value="form3"   />
                              <label for="flight">Flight</label>
                        </div>
                        <div class="f-item" >
                              <input type="radio" name="radio" id="cruise" value="form4"   />
                              <label for="cruise">Cruise</label>
                        </div>
                        <div class="f-item" >
                              <input type="radio" name="radio" id="flight_and_hotel" value="form5"   />
                              <label for="flight_and_hotel">Flight &amp; Hotel</label>      
                        </div>
                        <div class="f-item">
                              <input type="radio" name="radio" id="rent_a_car" value="form6"    />
                              <label for="rent_a_car">Rent a Car</label>
                        </div>
0
Comment
Question by:solution1368
3 Comments
 
LVL 10

Expert Comment

by:Monica P
ID: 38817572
Have used this block" SendMeQuote_Click " on codebehind page..

Your code is producing the Value "form5",on button click for option "Flight & Hotel"..Change the Value field to required option if needed.

Use GRoupname option to select only one value
http://www.devmanuals.com/tutorials/ms/aspdotnet/radiobutton.html

more example on http://www.java2s.com/Code/ASP/Asp-Control/RadiobuttonautopostbackC.htm
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38817667
We'll probably need to see more code. Your logic seems to work fine for me:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="_28008072.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <script runat="server">
            protected void SendMeQuote_Click(object sender, EventArgs e)
            {
                var x = Request.Form["radio"];
                Msg.Text = "Show: " + x;
            }
        </script>
        <div>
            <asp:Label runat="server" ID="Msg"></asp:Label>
            <div class="f-item">
                <input type="radio" name="radio" id="flight" value="form3" />
                <label for="flight">Flight</label>
            </div>
            <div class="f-item">
                <input type="radio" name="radio" id="cruise" value="form4" />
                <label for="cruise">Cruise</label>
            </div>
            <div class="f-item">
                <input type="radio" name="radio" id="flight_and_hotel" value="form5" />
                <label for="flight_and_hotel">Flight &amp; Hotel</label>
            </div>
            <div class="f-item">
                <input type="radio" name="radio" id="rent_a_car" value="form6" />
                <label for="rent_a_car">Rent a Car</label>
            </div>
            <asp:Button runat="server" ID="SendMeQuote" OnClick="SendMeQuote_Click" Text="Click" />
        </div>
    </form>
</body>
</html>

Open in new window


Screenshot
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 38819445
Any reason for not using asp.net RadioButtonList?

<asp:Label runat="server" ID="Msg"></asp:Label>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem Text="Flight" Value="form3"/>
            <asp:ListItem Text="Cruise" Value="form4"/>
            <asp:ListItem Text="Flight & Hotel" Value="form5"/>
            <asp:ListItem Text="Rent a Car" Value="form6"/>
        </asp:RadioButtonList>
        <asp:Button ID="SendMeQuote" runat="server" Text="Button" OnClick="SendMeQuote_Click" />

protected void SendMeQuote_Click(object sender, EventArgs e)
{
        Msg.Text = "Show: " + RadioButtonList1.SelectedValue;
}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question