How to code my main page for code behind to fire on a submit button click

Posted on 2008-10-01
Last Modified: 2011-08-18
I have zero experience with code behind be kind.

I would like to use it for inserting or updating code to my SQL database.  I found some code behind that looks like it will work well for my needs.  Can someone tell me how to code my main page for this? I am using a submit button and VB.

Here is URL for the code behind..

I am using code behind for my calendar popup...stolen from web also.  But that is callled from the image of a calendar on my page.

I am include some code snippet - I have the submit button there but only show 12 fields - there are probably about 60 fields that I will be writing  to my database.

<title>Patient Safety Report</title>
<script type="text/vb" runat="server">
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
               Me.drpdwnEvent_SelectedIndexChanged(Me, New EventArgs())
               Dim strAccountNumber As String = Request.QueryString("AccountNumber")
              Dim strName As String = Request.QueryString("Name")
              Dim strBirthDateTime As String = Request.QueryString("BirthDateTime")
              Dim strServiceDateTime As string = Request.QueryString("ServiceDateTime")
              Dim strStatus As String = Request.QueryString("Status")
              Dim strLocationName As String = Request.QueryString("LocationName")
              Me.CheckBox1_CheckedChanged(Me, New EventArgs())
              Me.cmdSubmit_Clicked(Me, New EventArgs())            
      		End Sub          
Sub cmdSubmit_Click(byVal sender as Object, ByVal e As System.EventArgs)
            SQLIncidentTemp.InsertCommand=_"Insert INTO IncidentTmp(ID,PtAcct, PtName, PtDob, PtDos, PtStat, PtLoc, Event, Facility, EventDept, EventLoc, EventDate, EventTime}"&
            &_"VALUES(100,PtAcct, PtName, PtDob, PtDos, PtStat, PtLoc, Event, Facility, EventDept, EventLoc, EventDate, EventTime);"      
              Dim PtAcct As New ControlParameter("PtAcct", "PtAcct", "Text")
              Dim PtName As New ControlParameter("PtName", "PtName", "Text")
              Dim PtDob As New ControlParameter("PtDob", "PtDob", "Text")
              Dim PtDos As New ControlParameter("PtDos", "PtDos", "Text")
              Dim PtStat As New ControlParameter("PtStat", "PtStat", "Text")
              Dim PtLoc As New ControlParameter("PtLoc", "PtLoc", "Text")
              Dim Event As New ControlParameter("Event", "Event", "Selected Value")
              Dim Facility As New ControlParameter("Facility", "Facility", "Selected Value")
              Dim EventDept As New ControlParameter("EventDept", "EventDept", "Selected Value")
              Dim EventLoc As New ControlParameter("EventLoc", "EventLoc", "Selected Value")
              Dim EventDate As New ControlParameter("EventDate", "EventDate", "Text")
              Dim EventTime As New ControlParameter("EventTime", "EventTime", "Selected Value")
               cmdSubmit.visible = False
               End Try
            End Sub

Open in new window

Question by:aninec
  • 5
  • 3
LVL 21

Expert Comment

ID: 22614709
Well anything that has a .Text you have to create a text box for.  also... the code you chose is a little more complicated than necessary...i think there are simpler ways to do this...VS has a lot of wizards for your convenience...  i suggest you visiting

Author Comment

ID: 22614820
I am not using visual studios... I am using Expression Web so no Wizards for this at least not what I have seen.
LVL 21

Expert Comment

ID: 22615050
oh...ok...well still...ok...i see..well you could just take that whole page load sub and place in the code behind...also...can you provide a link to where you found this code....Usually also you load your first data view in Load...But i'm sorry...I can't proceed further...what exactly are you trying to do with this code?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 22615335
The code is in the URL above.  I am going to modifiy it for my datasource and my text fields.  I want to call that code behind from my webpage. Obviously the code behind will be in a code behind file in my website..not calling it from that URL.

My question is.... How do I code my webpage to call that code behind file when I click the submit button.
LVL 21

Accepted Solution

silemone earned 500 total points
ID: 22615531
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>  will make the page look to the code behind...i.e..

place this in Default2.aspx...and it tells it to look for this file for code/events of page

and is the submit button an aspnet button?

in the link you provided:

 Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click

see at the end where it says Handles...well whatever name is in front of the .Click, name your <asp:button id ="LinkButton1... or <asp:LinkButton id= "LinkButton1"   or you can change the Name in front of the .Click to reflect the name you have already chose...
LVL 21

Expert Comment

ID: 22615729
if it's an <input type = submit.... then

i.e <input type="submit" id="submitter" runat="server" onserverclick="clickMe"...then

or you could just add handles submitter.ServerClick


Author Closing Comment

ID: 31501976
LVL 21

Expert Comment

ID: 22617972
happy to have helped...

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to limit User Input 2 33
Problem to line 23 74
Passing data between Forms 3 28
how to remove error in database 6 36
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

733 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