Link to home
Start Free TrialLog in
Avatar of Stiggley
Stiggley

asked on

form to database asp.net web application with VB

Hi Everyone,

     I have written several vb applications that interface with our advantagedatabase, but I am currently working on MY FIRST asp.net web application.  I need the user to answer a few questions and click my submit button.  Once the button is clicked I need to send the information on the form into a table on my database.  I would rather not use access.  I have an older sybase database and I know how to talk with it fine in a standard vb app.  I guess im just not sure how vb works with asp.net.  I have created the page already.  If i go to my design view I can add controls.  If i double click on the controls it takes me to the vb code.  However if i write code for those controls, it does nothing on my web app when I run it.  If i go to my asp.net source code it also has the controls coded.  I would like the submit button to be able to start my vb app which would pull all the info into my vb function and submit it to my database.

Any direction would be greatly appreciated

THANKS!
Stiggley
Avatar of gamarrojgq
gamarrojgq

Hi,

What kind of code you wrote for the controls? are you bound your controls to a DataSoucre? or you are setting the values of the controls programatically?

Can you post an example?

Here is a link where you can see an example

http://www.beansoftware.com/ASP.NET-Tutorials/Connecting-Access-SQL-Server.aspx, it uses acces and SQL server but the it could give you an idea


Avatar of Stiggley

ASKER

Hi and thank you....

I have not actually started connecting to the database because I am confused on just basic funtionality between asp and vb.  for example... I tried entering code where if you click submit one of the text boxes text changes.  It does not work.. or If i changed the selection of a radio button through the code it would not work.. below is the template for both the asp and the vb.

Here is my asp code  and below under the line is my vb code.... I f i try to type any code for my submit button on the vb code it will not execute in the web app

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
<%@ Import Namespace=" " %>

<!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>Dynamic Email "opt-out" Survey</title>
    <style type="text/css">
        .style1
        {
            text-indent: -.25in;
            font-size: 11.0pt;
            font-family: Calibri, sans-serif;
            margin-left: .5in;
            margin-right: 0in;
            margin-top: 0in;
            margin-bottom: .0001pt;
        }
    </style>
</head>
<body>
<center>
    <form id="form1" runat="server">
    <div>
   
    </div>
    <p>
        &nbsp;</p>
    <p>
        &nbsp;</p>
<p>
 <img alt="top" src="top.jpg" style="height: 255px; width: 520px" /> </br> Please
        Answer the Following Questions and click "Submit":

</p>
   
   
    <p>
     
        Please Enter Your Email Address:  </br>
        <asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox> </br>
       
   
   
    </p>
    <p>
          Please Confirm Your Email Address: </br>
        <asp:TextBox ID="TextBox2" runat="server" Width="200px"></asp:TextBox> </br>
       
         
    </p>
   
 
    <p class="style1" style="mso-list: l0 level1 lfo1">
        <![if !supportLists]><span style="mso-fareast-font-family:Calibri;color:black">
        <span style="mso-list:Ignore">
        <span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </span></span></span><![endif]><span style="color:black">Are you still suffering
        from back pain, neck pain, or migraine headaches?&nbsp; </span>
        <asp:radiobuttonlist id="radio1" runat="server">
  <asp:listitem id="option1" runat="server" value="Yes" />
  <asp:listitem id="option2" runat="server" value="No" />
 
</asp:radiobuttonlist>
    </p>
 
    <p class="style1" style="mso-list: l0 level1 lfo1">
        <span style="color:black">Would you recommend us to a friend
        with back or neck pain?
        <asp:radiobuttonlist id="radio" runat="server">
  <asp:listitem id="Option3" runat="server" value="Yes" />
  <asp:listitem id="Option4" runat="server" value="No" />
 
</asp:radiobuttonlist>
        </span></p>
   
   
 
<p>
    <asp:Button ID="Button1" runat="server" Text="Submit"    />
    </p>
   
   
   
   
 
    </form>
<p>
    &nbsp;</p>
<p>
    &nbsp;</p>
<p>
    &nbsp;</p>
    </center>
</body>
</html>

__________________________________________________________________________---

now the vb code:

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

 

   
   
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click


    End Sub
End Class
Ok, in the vb code you do not have any code jet, so if you want to change the text property of the textboxes on the submit button you code for that button shoul be

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        TextBox1.Text = "Text Added in Codebehind"
        TextBo12.Text = "This one too"
    End Sub

If this is your first asp.net application perhaps there are somethings you need to know: (if you know it already, please forgiveme)

1.- The vb.code executes on the Server not in the client
2.- Each time you click on a button the page make a post and returns to the Server to executes the code for that button
3.- Every time the page return to the server runs the PAGE LOAD event, so if you have code there that asign values to the Textboxes this will discard the changes made by the user, so you have to check if its the first time the page is rendered or if is a Post event called by the user (cliking a button for example)

ASKER CERTIFIED SOLUTION
Avatar of Stiggley
Stiggley

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well the User will see the changes AFTER the pages executes all the code, so, let say the user enter his email in TextBox1, when click Submit button, the email entered by the users goes to the server and in the PAGE LOAD event you can see that value, if there is no code in the PAGE LOAD event that change the TextBox1 text property, it will execute the code in the BUTTON1_CLICK event, here you can still see the email entered by the user, if in this event you have this code

TextBox1.Text = "Text Added in Codebehind"

when the page reloads, the users will see "TEXT ADDED IN CODEBEHIND" instead of the email he entered before, but, if you do not have code that changes the TextBox1 text property, when the pages reloads the user will see the same email he entered

I recommend you to watch this videos

http://www.asp.net/general/videos/intro-to-web-forms

http://www.asp.net/general/videos/page-lifecycle-events

http://www.asp.net/general/videos/intro-to-aspnet-controls

http://www.asp.net/general/videos/submit-and-postback

Thank you very much