AndrewPetersV
New Member
Hi All,<BR><BR>I have a form that posts back to itself. I have a button_onclick event called after the form is submitted. Anyone ever had luck passing form data either through a post or get method to a Button_OnClick event. I've gotten the same code to work when using the Page_Onload event. List below is sample code of what i'm talking about. When i turn page tracing on, the form and querystring values are getting passed but its like the Onclick event when a form posts to itself doesn't work. Please either contact me via email or reply to this....<BR><BR>This doesn't works<BR><BR><%@ Page Trace="true"%> <BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.SQL" %><BR><BR><script language="VB" runat="server"><BR> <BR> Sub steve_click(Sender As Object, e As EventArgs) <BR><BR> Dim Idiot as string = Request.form("text1")<BR> response.write(request("text1"))<BR> Dim myConnection As SQLConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=aspfree")<BR> Dim insertString As String<BR> Dim MyCommand As SQLCommand<BR><BR> InsertString = "Insert into Guestbook (Name) VALUES (@Idiot)"<BR><BR> MyCommand = New SQLCommand(InsertString, MyConnection)<BR><BR> MyCommand.Parameters.Add(New SQLParameter("@Idiot", SQLDataType.VarChar, 50))<BR> MyCommand.Parameters("@Idiot").Value = http://aspmessageboard.com/archive/index.php/request.form("text1")<BR> myConnection.Open()<BR> myCommand.Execute()<BR> myConnection.Close()<BR> <BR> <BR> End Sub<BR><BR></script><BR><BR><BR><html><BR><BR><head><BR><title>New Page 1</title><BR></head><BR><body><BR><p align="center"><BR><b><BR><font face="Arial"><strong><big>Guest Book Entry ASP.NET style!</big></strong></font></b></p><BR><form method="Post"><BR><div align="center"><BR> <center><BR><table border="0" cellpadding="2" cellspacing="2"><BR> <tr><BR> <td bgcolor="#800000"><asp:Label id="Label1" tooltip="Enter Your Name" Font-Name="Arial" Forecolor="#ffffff" Text="Name" runat="server"/></td><BR> <td bgcolor="#C0C0C0"><asp:textbox id="text1" name="Name" size="30" runat="server"/></td><BR> </tr><BR> <tr><BR> <td align="center" colspan="2" bgcolor="#800000"><asp:Button id="Button1" onclick="steve_click" Name="btnSubmit" type="Submit" text="Submit Message" runat="server"/></td><BR> </tr><BR></table><BR> </center><BR></div><BR> <BR></form><BR></body><BR><BR><BR>This page submits to another page and uses the Page Onload event<BR><BR><%@ Page Trace="true"%><BR><html><BR><head><BR><title>New Page 1</title><BR></head><BR><body><BR><p align="center"><BR><b><BR><font face="Arial"><strong><big>Guest Book Entry ASP.NET style!</big></strong></font></b></p><BR><form method="POST" action="default3.aspx"><BR><div align="center"><BR> <center><BR><table border="0" cellpadding="2" cellspacing="2"><BR> <tr><BR> <td bgcolor="#800000"><asp:Label id="Label1" tooltip="Enter Your Name" Font-Name="Arial" Forecolor="#ffffff" Text="Name" runat="server"/></td><BR> <td bgcolor="#C0C0C0"><asp:textbox id="text1" Name="Idiot" size="30" runat="server"/></td><BR> </tr><BR> <tr><BR> <td align="center" colspan="2" bgcolor="#800000"><asp:Button type="Submit" text="Submit Message" runat="server"/></td><BR> </tr><BR></table><BR> </center><BR></div><BR></form><BR></body><BR></html><BR><BR>Second page has the database logic in a compiled dll and it works fine.<BR><BR><%@ Page Trace="true"%><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.SQL" %><BR><BR><script language="VB" runat="server"><BR> <BR><BR> Sub Page_Load(sender As Object, e As EventArgs) <BR> <BR><BR> Idiot = Request.form("text1")<BR><BR> Dim PostMsg As New ASPFree.MessageText<BR> PostMsg.GetNewHeadLines(Idiot)<BR> <BR> End Sub<BR><BR></script><BR><html><BR><head><BR></head><BR><body><BR>Body written<BR></body><BR></html><BR><BR>.VB file that has the db logic in it.<BR><BR>Imports System<BR>Imports System.Data<BR>Imports System.Data.SQL<BR>Namespace ASPFree<BR><BR><BR> Public Class PostDetails<BR> <BR> Public Idiot As String<BR><BR> End Class<BR><BR> Public Class MessageText<BR><BR><BR> Public Sub GetNewHeadlines(Idiot as String)<BR><BR> ' Create Instance of Connection and Command Object<BR> Dim myConnection As SQLConnection = new SQLConnection(aspfreedb.ConnectionString)<BR> Dim insertString As String<BR> Dim MyCommand As SQLCommand<BR><BR> InsertString = "Insert into Guestbook (Name) VALUES (@Idiot)"<BR><BR> MyCommand = New SQLCommand(InsertString, MyConnection)<BR><BR> MyCommand.Parameters.Add(New SQLParameter("@Idiot", SQLDataType.VarChar, 50))<BR> MyCommand.Parameters("@Idiot").Value = Idiot<BR><BR> <BR> Try <BR> ' Open the connection and execute the Command<BR> myConnection.Open()<BR> myCommand.Execute()<BR> Catch e As Exception<BR> ' An error occurred, pass the exception up<BR> throw e<BR> Finally <BR> ' Close the Connection<BR> If myConnection.State = DBObjectState.Open then<BR> myConnection.Close()<BR> End If<BR> End Try<BR> <BR> <BR> End Sub<BR> <BR> End Class<BR><BR>End Namespace<BR><BR>Helper db connection .VB file<BR><BR>Imports System<BR>Imports System.Web<BR>Imports System.Collections<BR><BR>Namespace ASPFree<BR><BR><BR> Public Class ASPFreedb<BR> <BR> Shared m_ConnectionString As String<BR><BR> '********************************************** *********<BR> '<BR> ' ASPFreeDB.ConnectionString Property<BR> '<BR> ' The ASPFreeDB.ConnectionString property encapsulates<BR> ' a callout to the ASP+ Config System to obtain the<BR> ' database connection string for the application.<BR> '<BR> '********************************************** *********<BR><BR> Shared ReadOnly Property ConnectionString As String <BR> <BR> Get <BR><BR> ' Pull the ConnectionString from the ASP+ AppSettings section.<BR> ' Cache in static field for faster repeat access.<BR><BR> If m_ConnectionString = "" Then<BR><BR> Dim appsetting As Hashtable = CType(HttpContext.Current.GetConfig("appsettings"), Hashtable) <BR> m_ConnectionString = CStr(appsetting("DSN"))<BR><BR> If m_ConnectionString = "" Then<BR> throw new Exception("ASPFree DSN Value not set in Config.web")<BR> End if<BR><BR> End If<BR><BR> ' Return the Connection String<BR> return m_connectionString<BR><BR> End Get<BR> <BR> End Property<BR> <BR> End Class<BR> <BR>End Namespace<BR><BR>-- <BR>* ----------------------------------------- *<BR>* Steve Schofield [email protected]<BR>* Webmaster<BR>* http://www.aspfree.com<BR>* http://www.abc2xml.com<BR>* ----------------------------------------- *allright dude,<BR><BR>if you're posting back to yourself... you've got to access the form value a bit differently... like this:<BR>---------------------<BR>text1.Text<BR>---------------------<BR><BR>if you've done any VB application programming this will look very familiar... just access them with that object model and you'll do just fine...<BR><BR>Joel M