Solved

asp.net read html controls

Posted on 2013-01-24
3
393 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
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 33
Exception in Log4Net 1 17
Open form in the top right hand corner of screen 5 18
Copy/Clone an object. 9 10
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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now