|
 |
aspx thread: [aspx]Sub page_load vs Sub Button_onclick?
Message #1 by "Brandy" <brandmo@h...> on Fri, 19 Jan 2001 15:28:51 +0100
|
|
What is the difference between sub page_load and sub button_onclick?
if I make a submit button and want an event to happen when I click the
button nothing happens and I dont get my data from the tables into my
dropdownlist either but if I put my code in the sub page_load I got my data
from the tables in my dropdown..??
I want to load my info in the dropdown list and then I have some info that I
want to be inserted to a SQL database, Do I have to make 2 sub procedyre
where one loads the page and another inserts my data when I submit my
button?
Regards
Brandy
Message #2 by "Alessandro Betti" <betti@t...> on Fri, 19 Jan 2001 15:50:19 +0100
|
|
Hi...
Did you put your buttons in a form tag?
Try this.
<script language="vb" runat="server">
sub button_onclick(s as Object,e as eventArgs)
....Something
end sub
</script>
<html>
<body>
<Form Runat="server">
<asp:button id=bottone onclick="button_onclick" runat="server"/>
</Form>
</body>
</htmL>
Ciao
Alessandro
-----Original Message-----
From: Brandy <brandmo@h...>
To: ASP+ <aspx@p...>
Date: 19 January 2001 15:36
Subject: [aspx] [aspx]Sub page_load vs Sub Button_onclick?
>
>
>What is the difference between sub page_load and sub button_onclick?
>
>if I make a submit button and want an event to happen when I click the
>button nothing happens and I dont get my data from the tables into my
>dropdownlist either but if I put my code in the sub page_load I got my data
>from the tables in my dropdown..??
>
>I want to load my info in the dropdown list and then I have some info that
I
>want to be inserted to a SQL database, Do I have to make 2 sub procedyre
>where one loads the page and another inserts my data when I submit my
>button?
>
>Regards
>Brandy
Message #3 by "Jonathan Goodyear" <jon@a...> on Fri, 19 Jan 2001 09:52:42 -0500
|
|
You got it: The Page_Load event is where you load your controls with data
(be sure to use the Page.IsPostBack property so that you only load your
controls with data the first time the page is loaded. Example:
Sub Page_Load(Sender As Object, e As EventArtgs)
If Not Page.IsPostBack Then
'Load your controls with data here
End If
End Sub
Here's your button event:
Sub button1_click(Sender As Object, e As EventArgs)
'Put code here to get form data and insert into database
End Sub
You assign a server event to a button control like this:
<asp:Button id="button1" onclick="button1_click" runat="server" />
Hope this helps!
----jonathan goodyear, mcsd, mcp, cls
president@a...
----- Original Message -----
From: "Brandy" <brandmo@h...>
To: "ASP+" <aspx@p...>
Sent: Friday, January 19, 2001 9:28 AM
Subject: [aspx] [aspx]Sub page_load vs Sub Button_onclick?
>
>
> What is the difference between sub page_load and sub button_onclick?
>
> if I make a submit button and want an event to happen when I click the
> button nothing happens and I dont get my data from the tables into my
> dropdownlist either but if I put my code in the sub page_load I got my
data
> from the tables in my dropdown..??
>
> I want to load my info in the dropdown list and then I have some info that
I
> want to be inserted to a SQL database, Do I have to make 2 sub procedyre
> where one loads the page and another inserts my data when I submit my
> button?
>
> Regards
> Brandy
Message #4 by "Brandy" <brandmo@h...> on Fri, 19 Jan 2001 17:08:05 +0100
|
|
I have the button in a form tag yes.. I have sorted out that I need 2 sub
procedyre one for page_load and one for button_click
But I havent sorted it out the command to execute my button_click and why it
is executed ..
In the page_load i am filling the dropdownlist with the dataset object with
data from my info in the table tekniker, but I get an Attempted to
dereference a null object reference. error which is because of the
"myCommand.ExecuteNonQuery()" expression if i rem it out I get the page
loaded , but I dont get inserted my data into the SQL when I submit my
Insert data button..
I have pasted my code under here if its needed for sorting out the error..
Is it anyone who are able to tell me why I get this error and how to fix it?
Regards
Brandy
<%@ Import Namespace="System.Data.SQL" %>
<%@ Import Namespace="System.Data" %>
<html><head>
<title>Arbeidsordre registrering for tekniker</title>
<meta content="Navigator 4.0" name=vs_targetSchema>
<script language=VB id=Script1 runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
If Not Page.IsPostBack Then
Dim DS As New DataSet
Dim MyCommand As SQLDataSetCommand
.
dim strconn as string
dim strSQL as string
strconn = "server=knutepunktet;uid=sa;pwd=;database=sak"
strSQL="select * from tekniker"
MyCommand = New SQLDataSetCommand(strSQL,Strconn)
MyCommand.FillDataSet(ds, "Tekniker")
TeknikerID.DataSource=ds.Tables("Tekniker").DefaultView
Page.DataBind()
end if
End Sub
public sub Insertdata_click(ByVal Sender As Object, ByVal E As EventArgs)
Dim intAvsluttet As Integer
Dim SSQl As String = "Insert into Transaksjon values (@Aonummer,
@Startet, @Aktivitet,@Tid, @avsluttet) "
'Dim strConn as string
'Dim MyConnection As SQLConnection = New SQLConnection
Myconnection = new
SQLConnection("server=knutepunktet;uid=sa;pwd=;Database=sak")
Dim myCommand As SQLCommand
Mycommand = new SQLcommand(sSQL,strconn)
MyCommand.Parameters.Add(New SQLParameter("@Aonummer",
Data.SQL.SQLDataType.Int, 50))
MyCommand.Parameters("@Aonummer").Value = request.form("Aonummer")
MyCommand.Parameters.Add(New SQLParameter("@TeknikerID",
SQLDataType.VarChar,1))
MyCommand.Parameters("@TeknikerID").Value
request.form("TeknikerID")
MyCommand.Parameters.Add(New SQLParameter("@Startet",
SQLDataType.SmallDateTime))
MyCommand.Parameters("@Startet").Value = now()
MyCommand.Parameters.Add(New SQLParameter("@Aktivitet",
SQLDataType.VarChar, 50))
MyCommand.Parameters("@Aktivitet").Value = request.form("Aktivitet")
MyCommand.Parameters.Add(New SQLParameter("@Tid", SQLDataType.Int,
50))
MyCommand.Parameters("@Tid").Value = request.form("Tid")
MyCommand.Parameters.Add(New SQLParameter("@Avsluttet",
SQLDataType.Int))
If request.form("Avsluttet") = "on" Then
intAvsluttet = 1
Else
intAvsluttet = 0
End If
MyCommand.Parameters("@Avsluttet").Value = intAvsluttet
myCommand.ActiveConnection.Open()
myCommand.ExecuteNonQuery()
End Sub
</script>
<meta content=VBScript name=vs_defaultClientScript></head>
<body text=#0000ff bgColor=#ffffff>
<Form action="webform1.aspx" method="post" runat="server" ID=Form1>
<p><asp:label id=Label1
runat="server">Aonummer</asp:label>
<asp:textbox id=AOnummer runat="server"
height="24" width="48"></asp:textbox></p>
<p><asp:label id=Label2
runat="server">Tekniker</asp:label>  
;
<asp:dropdownlist id=TeknikerID
runat="server" datatextfield="Navn"></asp:dropdownlist></p>
<p><asp:label id=Label3 runat="server">
Arbeidsordrestart</asp:label>
<asp:textbox id=Startet runat="server" Width="50"
Height="24"></asp:textbox></p>
<p><asp:label id=Label4
runat="server">Aktivitet</asp:label> &nbs
p;
<asp:TextBox id=Aktivitet runat="server" Height="66"
Width="156"></asp:TextBox></p>
<p> </p>
<p><asp:label id=Label5 runat="server">Forbrukt
tid</asp:label>
<asp:textbox id=Tid runat="server" Width="60" Height="24"></asp:textbox></p>
<p><asp:label id=Label6
runat="server">Avsluttet</asp:label> &nbs
p;
<asp:checkbox id=Avsluttet runat="server" Width="10"
Height="39"></asp:checkbox></p>
<p>
<asp:Button id=Button1 onclick ="insertdata_click" runat="server"
Text="Button"></asp:Button>
</Form></P>
</body></html>
----- Original Message -----
From: "Alessandro Betti" <betti@t...>
To: "ASP+" <aspx@p...>
Sent: Friday, January 19, 2001 3:50 PM
Subject: [aspx] Re: [aspx]Sub page_load vs Sub Button_onclick?
> Hi...
> Did you put your buttons in a form tag?
>
> Try this.
> <script language="vb" runat="server">
> sub button_onclick(s as Object,e as eventArgs)
>
> ....Something
>
> end sub
> </script>
> <html>
> <body>
> <Form Runat="server">
>
> <asp:button id=bottone onclick="button_onclick" runat="server"/>
>
> </Form>
> </body>
> </htmL>
>
> Ciao
> Alessandro
>
> -----Original Message-----
> From: Brandy <brandmo@h...>
> To: ASP+ <aspx@p...>
> Date: 19 January 2001 15:36
> Subject: [aspx] [aspx]Sub page_load vs Sub Button_onclick?
>
>
> >
> >
> >What is the difference between sub page_load and sub button_onclick?
> >
> >if I make a submit button and want an event to happen when I click the
> >button nothing happens and I dont get my data from the tables into my
> >dropdownlist either but if I put my code in the sub page_load I got my
data
> >from the tables in my dropdown..??
> >
> >I want to load my info in the dropdown list and then I have some info
that
> I
> >want to be inserted to a SQL database, Do I have to make 2 sub procedyre
> >where one loads the page and another inserts my data when I submit my
> >button?
> >
> >Regards
> >Brandy
>
>
>
Message #5 by John Pirkey <mailjohnny101@y...> on Fri, 19 Jan 2001 08:32:44 -0800 (PST)
|
|
try adding the type attribute to your submit button. so that it looks like this:
<asp:Button type="submit" id="button1" text="Run Query" OnClick="InsertData_Click"
runat="server" />
to get the routine to run with the correct form values.
hope this helps,
john
--- Brandy <brandmo@h...> wrote:
> I have the button in a form tag yes.. I have sorted out that I need 2 sub
> procedyre one for page_load and one for button_click
>
> But I havent sorted it out the command to execute my button_click and why it
> is executed ..
>
> In the page_load i am filling the dropdownlist with the dataset object with
> data from my info in the table tekniker, but I get an Attempted to
> dereference a null object reference. error which is because of the
> "myCommand.ExecuteNonQuery()" expression if i rem it out I get the page
> loaded , but I dont get inserted my data into the SQL when I submit my
> Insert data button..
>
>
> I have pasted my code under here if its needed for sorting out the error..
>
> Is it anyone who are able to tell me why I get this error and how to fix it?
>
> Regards
> Brandy
>
>
>
> <%@ Import Namespace="System.Data.SQL" %>
> <%@ Import Namespace="System.Data" %>
> <html><head>
> <title>Arbeidsordre registrering for tekniker</title>
> <meta content="Navigator 4.0" name=vs_targetSchema>
> <script language=VB id=Script1 runat="server">
>
> Sub Page_Load(Src As Object, E As EventArgs)
>
> If Not Page.IsPostBack Then
>
> Dim DS As New DataSet
> Dim MyCommand As SQLDataSetCommand
> .
> dim strconn as string
> dim strSQL as string
>
> strconn = "server=knutepunktet;uid=sa;pwd=;database=sak"
> strSQL="select * from tekniker"
>
> MyCommand = New SQLDataSetCommand(strSQL,Strconn)
> MyCommand.FillDataSet(ds, "Tekniker")
> TeknikerID.DataSource=ds.Tables("Tekniker").DefaultView
>
> Page.DataBind()
> end if
> End Sub
>
>
>
> public sub Insertdata_click(ByVal Sender As Object, ByVal E As EventArgs)
>
> Dim intAvsluttet As Integer
> Dim SSQl As String = "Insert into Transaksjon values (@Aonummer,
> @Startet, @Aktivitet,@Tid, @avsluttet) "
> 'Dim strConn as string
> 'Dim MyConnection As SQLConnection = New SQLConnection
>
> Myconnection = new
> SQLConnection("server=knutepunktet;uid=sa;pwd=;Database=sak")
>
> Dim myCommand As SQLCommand
>
> Mycommand = new SQLcommand(sSQL,strconn)
>
>
>
> MyCommand.Parameters.Add(New SQLParameter("@Aonummer",
> Data.SQL.SQLDataType.Int, 50))
> MyCommand.Parameters("@Aonummer").Value = request.form("Aonummer")
>
>
> MyCommand.Parameters.Add(New SQLParameter("@TeknikerID",
> SQLDataType.VarChar,1))
> MyCommand.Parameters("@TeknikerID").Value
> request.form("TeknikerID")
>
> MyCommand.Parameters.Add(New SQLParameter("@Startet",
> SQLDataType.SmallDateTime))
> MyCommand.Parameters("@Startet").Value = now()
>
> MyCommand.Parameters.Add(New SQLParameter("@Aktivitet",
> SQLDataType.VarChar, 50))
> MyCommand.Parameters("@Aktivitet").Value = request.form("Aktivitet")
>
> MyCommand.Parameters.Add(New SQLParameter("@Tid", SQLDataType.Int,
> 50))
> MyCommand.Parameters("@Tid").Value = request.form("Tid")
>
> MyCommand.Parameters.Add(New SQLParameter("@Avsluttet",
> SQLDataType.Int))
>
>
>
> If request.form("Avsluttet") = "on" Then
> intAvsluttet = 1
> Else
> intAvsluttet = 0
>
> End If
>
> MyCommand.Parameters("@Avsluttet").Value = intAvsluttet
>
> myCommand.ActiveConnection.Open()
>
>
> myCommand.ExecuteNonQuery()
> End Sub
>
>
>
> </script>
>
> <meta content=VBScript name=vs_defaultClientScript></head>
> <body text=#0000ff bgColor=#ffffff>
>
>
> <Form action="webform1.aspx" method="post" runat="server" ID=Form1>
>
> <p><asp:label id=Label1
> runat="server">Aonummer</asp:label>
> <asp:textbox id=AOnummer runat="server"
> height="24" width="48"></asp:textbox></p>
> <p><asp:label id=Label2
> runat="server">Tekniker</asp:label>  
> ;
> <asp:dropdownlist id=TeknikerID
> runat="server" datatextfield="Navn"></asp:dropdownlist></p>
> <p><asp:label id=Label3 runat="server">
> Arbeidsordrestart</asp:label>
> <asp:textbox id=Startet runat="server" Width="50"
> Height="24"></asp:textbox></p>
> <p><asp:label id=Label4
> runat="server">Aktivitet</asp:label> &nbs
> p;
> <asp:TextBox id=Aktivitet runat="server" Height="66"
> Width="156"></asp:TextBox></p>
> <p> </p>
> <p><asp:label id=Label5 runat="server">Forbrukt
> tid</asp:label>
> <asp:textbox id=Tid runat="server" Width="60" Height="24"></asp:textbox></p>
> <p><asp:label id=Label6
> runat="server">Avsluttet</asp:label> &nbs
> p;
> <asp:checkbox id=Avsluttet runat="server" Width="10"
> Height="39"></asp:checkbox></p>
> <p>
> <asp:Button id=Button1 onclick ="insertdata_click" runat="server"
> Text="Button"></asp:Button>
>
>
>
>
> </Form></P>
>
> </body></html>
>
>
>
>
> ----- Original Message -----
>
> From: "Alessandro Betti" <betti@t...>
> To: "ASP+" <aspx@p...>
> Sent: Friday, January 19, 2001 3:50 PM
> Subject: [aspx] Re: [aspx]Sub page_load vs Sub Button_onclick?
>
>
> > Hi...
> > Did you put your buttons in a form tag?
> >
> > Try this.
> > <script language="vb" runat="server">
> > sub button_onclick(s as Object,e as eventArgs)
> >
> > ....Something
> >
> > end sub
> > </script>
> > <html>
> > <body>
> > <Form Runat="server">
> >
> > <asp:button id=bottone onclick="button_onclick" runat="server"/>
> >
> > </Form>
> > </body>
> > </htmL>
> >
> > Ciao
> > Alessandro
> >
> > -----Original Message-----
> > From: Brandy <brandmo@h...>
> > To: ASP+ <aspx@p...>
> > Date: 19 January 2001 15:36
> > Subject: [aspx] [aspx]Sub page_load vs Sub Button_onclick?
> >
> >
> > >
> > >
> > >What is the difference between sub page_load and sub button_onclick?
> > >
> > >if I make a submit button and want an event to happen when I click the
> > >button nothing happens and I dont get my data from the tables into my
> > >dropdownlist either but if I put my code in the sub page_load I got my
> data
> > >from the tables in my dropdown..??
> > >
> > >I want to load my info in the dropdown list and then I have some info
> that
> > I
> > >want to be inserted to a SQL database, Do I have to make 2 sub procedyre
> > >where one loads the page and another inserts my data when I submit my
> > >button?
> > >
> > >Regards
> > >Brandy
> >
> >
> >
>
=====
----------------------------
John Pirkey
MCSD
John@S...
http://www.stlvbug.org
|
|
 |