Solved

asp.net read html controls

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query Help Top 1 and Distinct? 6 35
c# - Best approach for objects in functions 3 24
JSON Deserialize issue 6 26
Adding items to a C# list incrementally 5 29
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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