View Full Version : aspx registration form help

11-23-2010, 05:59 AM
Hey guys, so im really knew to aspx. I'm trying to create a registration form that connects to my access database and once a user registers it sends their information to the database.
But when i run my code it goes straight to catch as exception.
Here is my code,the code i have colored in red below may be causing the problem as i do not know exactly how to code it.
Suggestions would be appritiated.

<script runat="server">
Dim conn As New OleDbConnection("provider=microsoft.Jet.OLEDB.4.0;" & _
"Data source=" & AppDomain.CurrentDomain.BaseDirectory & "App_Data\webproject1.mdb")
Dim sqlcomand As New OleDbCommand

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

sqlcomand.Connection = conn
sqlcomand.CommandText = "insert into Registration " & _
"(FirstName,LastName,Age,Gender,Address,PostCode,Email,Username,Password) Values " & "('" & _
txtfirstname.Text & "'," & _
txtlastname.Text & "," & _
txtage.Text & ",'" & _
txtgender.Text & "'," & _
txtadress.Text & "," & _
txtemail.Text & ",'" & _
txtusername.Text & ",'" & _
txtpassword.Text & "')"
MsgBox("thanks for registering please login")

Catch ex As Exception
MsgBox("Error you cannot register")
End Try
End Sub

11-25-2010, 01:55 PM
The problem is with your msgbox() command.
The msgbox is trying to display on server.
It cannot hence error.
You need to use a clientscript (javascript) and use it with asp.net to display alert(). There are many articles on Internet on this.
Search "Page.ClientScript"

12-04-2010, 02:47 PM
Most simple way is to use:

Response.Write("<script type=\"text/javascript\"> alert('thanks for registering please login');</script>");

12-10-2010, 01:24 AM
Alternatively you could do something like this.

Dim scriptBlock As String = "<script type=""text/javascript"">"
scriptBlock += "alert('thanks for registering please login');"
scriptBlock += "</script>"
ClientScript.RegisterClientScriptBlock(Page.GetType(), "scriptKey", scriptBlock)

With this method you can access and modify the script block server side using the provided key "scriptKey".

Hope it helps.