Solved

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

Posted on 2008-10-01
8
184 Views
Last Modified: 2011-08-18
I have zero experience with code behind pages....so 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..

http://www.dotnetspider.com/resources/21175-Vb-net-code-insert-entered-repair-form-details-into-database.aspx

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())            

             

                                                               

               PtName.Text=strName

               PtAcct.Text=strAccountNumber

               PtDob.Text=strBirthDateTime

               PtDos.Text=strServiceDateTime

               PtStat.Text=strStatus 

               PtLoc.Text=strLocationName

               

      		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")

              SQLIncidentTemp.InsertParameters.Add(PtAcct)

              

              Dim PtName As New ControlParameter("PtName", "PtName", "Text")

              SQLIncidentTemp.InsertParameters.Add(PtName)

              

              Dim PtDob As New ControlParameter("PtDob", "PtDob", "Text")

              SQLIncidentTemp.InsertParameters.Add(PtDob)

              

              Dim PtDos As New ControlParameter("PtDos", "PtDos", "Text")

              SQLIncidentTemp.InsertParameters.Add(PtDos)

              

              Dim PtStat As New ControlParameter("PtStat", "PtStat", "Text")

              SQLIncidentTemp.InsertParameters.Add(PtStat)

              

              Dim PtLoc As New ControlParameter("PtLoc", "PtLoc", "Text")

              SQLIncidentTemp.InsertParameters.Add(PtLoc)

              

              Dim Event As New ControlParameter("Event", "Event", "Selected Value")

              SQLIncidentTemp.InsertParameters.Add(Event)

              

              Dim Facility As New ControlParameter("Facility", "Facility", "Selected Value")

              SQLIncidentTemp.InsertParameters.Add(Facility)

              

              Dim EventDept As New ControlParameter("EventDept", "EventDept", "Selected Value")

              SQLIncidentTemp.InsertParameters.Add(EventDept)

              

              Dim EventLoc As New ControlParameter("EventLoc", "EventLoc", "Selected Value")

              SQLIncidentTemp.InsertParameters.Add(EventLoc)

              

              Dim EventDate As New ControlParameter("EventDate", "EventDate", "Text")

              SQLIncidentTemp.InsertParameters.Add(EventDate)

              

              Dim EventTime As New ControlParameter("EventTime", "EventTime", "Selected Value")

              SQLIncidentTemp.InsertParameters.Add(EventTime)

              

              Try 

                SQLIncidentTmp.Insert()

              Finally

               cmdSubmit.visible = False

               End Try

            End Sub

Open in new window

0
Comment
Question by:aninec
  • 5
  • 3
8 Comments
 
LVL 21

Expert Comment

by:silemone
Comment Utility
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
http://msdn.microsoft.com/en-us/bb629407.aspx#asp
0
 

Author Comment

by:aninec
Comment Utility
I am not using visual studios... I am using Expression Web so no Wizards for this at least not what I have seen.
0
 
LVL 21

Expert Comment

by:silemone
Comment Utility
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?
0
 

Author Comment

by:aninec
Comment Utility
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.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 21

Accepted Solution

by:
silemone earned 500 total points
Comment Utility
<%@ 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...
0
 
LVL 21

Expert Comment

by:silemone
Comment Utility
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


0
 

Author Closing Comment

by:aninec
Comment Utility
Perfect...thanks!
0
 
LVL 21

Expert Comment

by:silemone
Comment Utility
happy to have helped...
cheers
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Access query that references subform 5 35
Code enhancement 5 12
Showdialog 8 20
How to Add / Edit Windows Menu 4 23
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now