Solved

asp.net read html controls

Posted on 2013-01-24
3
402 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

632 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