none
submit radio button and a textbox values to SQL db RRS feed

  • Question

  • Hi all,

    this is my first time so please go easy on me Smile.

    I am having trouble in trying to submit my web form to my db. I am using the SQL Server Express Ed that comes with VWD.

    I am new to C# and I am not sure on what to do in order to get the page to submit to my db. I have followed some examples I found online but still no joy.

    I have 9 radio buttons each in a group of 3. I have provided them with groupnames, Q1_Red, Q1_Black, Q1_Blue. The user does not necessarily have to answer all questions on the page so they could go page2 without filling out the form. Within this page is also a text box that if the user has input a value that is submitted to a column in the db (column name Q1_comments).

    I would like the db connnection to be held in the web.config file and called each time the submit button is pressed each time. So whenever a user hits submit the values are stored in the db and the person is then directed to the next page (in this case page2.aspx).

    Can anyone provide me with any insight on how to do this? I am basically on the code behind page for page1.aspx and have the btn_submit event handler waiting for some code.

    Is it best to do this using stored procedures? If so how do I tell the page to submit to the stored proc?

    I am really new to all of this so any help or pointer would be great.

    Thanks in advance,
    J

    ============
    My code

    page1.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="page1.aspx.cs" Inherits="page1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td colspan="4">Would you buy?</td>
                </tr>
                <tr>
                    <td></td>
                    <td>Yes</td>
                    <td>No</td>
                    <td>Maybe</td>
                </tr>
                <tr>
                    <td>Red</td>
                    <td>
                        <asp:RadioButton ID="R_Yes" GroupName="Q1_Red" runat="server" /></td>
                    <td>
                        <asp:RadioButton ID="R_No" GroupName="Q1_Red" runat="server" /></td>
                    <td>
                        <asp:RadioButton ID="R_Maybe" GroupName="Q1_Red" runat="server" /></td>
                </tr>
                <tr>
                    <td>Black</td>
                    <td>
                        <asp:RadioButton ID="Blk_Yes" GroupName="Q1_Black" runat="server" /></td>
                    <td>
                        <asp:RadioButton ID="Blk_No" GroupName="Q1_Black" runat="server" /></td>
                    <td>
                        <asp:RadioButton ID="Blk_Maybe" GroupName="Q1_Black" runat="server" /></td>
                </tr>
                <tr>
                    <td>Blue</td>
                    <td>
                        <asp:RadioButton ID="Blu_Yes" GroupName="Q1_Blue" runat="server" /></td>
                    <td>
                        <asp:RadioButton ID="Blu_No" GroupName="Q1_Blue" runat="server" /></td>
                    <td>
                        <asp:RadioButton ID="Blu_Maybe" GroupName="Q1_Blue" runat="server" /></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="4">
                      Additional comments:  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
                </tr>
            </table>
            <br />
        </div>
            <asp:Button ID="btn_Submit" runat="server" Text="Next page" OnClick="btn_Submit_Click" />
        </form>
    </body>
    </html>


    ============

    Wednesday, November 28, 2007 12:56 PM

Answers