Solved

asp.net read html controls

Posted on 2013-01-24
3
396 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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