Click to See Complete Forum and Search --> : Calling a sub within a page?


Calmaris
01-04-2004, 02:36 AM
I'm trying to call the script with a sub call this: dotheregistermember(Sender as Object, e as EventArgs)

if the user's name doesn't exist already. But I get an error

Compiler Error Message: BC30455: Argument not specified for parameter 'e' of 'Public Sub dotheregistermember(Sender As Object, e As System.EventArgs)'.

How Do I call the other sub?
<%@ Page Language="VBScript" Debug="true" aspcompat=true %>


<script runat="server">
Sub registermember (Sender as Object, e as EventArgs)
Try
Dim dbConn, dbQuery, recordsetDB, loginfound, User_Id,tstring
Dim Password, First_Name, Last_Name, Mem_City, Mem_Address, Postal_Code, Home_Phone_Num, Cell_Num, Marital_Status
Dim Occupation_School, Email_1, Email_2, Province, Country, State, Apt_Num, offlinenow
Dim namecheck, usernamecheck
User_Id = request.Form("User_Id")
Password = request.Form("Password")
First_Name = request.form("First_Name")
Last_Name = request.form("Last_Name")
Mem_City = request.form("City")
Mem_Address = request.form("Address")
Postal_Code=request.form("Postal_Code")
Home_Phone_Num=request.form("Home_Phone_Num")
Cell_Num=request.form("Cell_Num")
Marital_Status=request.form("Marital_Status")
Occupation_School=request.form("Occupation_School")
Email_1 = request.form("Email_1")
Email_2 = request.form("Email_2")
Province = request.form("Province")
State = request.form("State")
Apt_Num = request.form("Apt_Num")
Country = request.form("Country")
offlinenow = True

dbConn = Server.CreateObject("ADODB.Connection")
dbConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\wwwroot\mess\databases\members.mdb")

namecheck =" Select User_Id From Members WHERE User_Id = '" & User_Id & "' "
usernamecheck = dbconn.execute(namecheck)

If NOT usernamecheck.eof THEN

woops.Visible = true

ELSE

successful.visible = true

dotheregistermember(Sender as Object, e as EventArgs)


End if
Finally


End Try

</script>

<script runat="server">
Sub dotheregistermember (Sender as Object, e as EventArgs)

Try

tstring = " INSERT INTO Members ( User_Id, Password, First_Name, Last_Name, Mem_City, Mem_Address,Postal_Code, Home_Phone_Num, Cell_Num, Marital_Status, Occupation_School, Email_1, Email_2," & _
" Province, State, Apt_Num, Country, offlinenow)" & _
" VALUES ( '" & User_Id & "', '" & Password & "','" & First_Name & "','" & Last_Name & "','" & Mem_City & "', '" & Mem_Address & "', '" & Postal_Code & "', '" & Home_Phone_Num & "', " & _
" '" & Cell_Num & "', '" & Marital_Status & "', '" & Occupation_School & "', '" & Email_1 & "', '" & Email_2 & "', '" & Province & "', '" & State & "', '" & Apt_Num & "', '" & Country & "', True)"
recordsetDB = dbconn.execute(tstring)
'response.write("Thank you for Updating your Member Information")
'response.redirect("Home.aspx")

Finally


End Try

End sub
</script>
<html>
<head>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>WELCOME TO THE REGISTRATION FORM</title>
</head>

<body background="grback.jpg">

<form method="Post" runat="Server"><p>&nbsp;</p>

<p>User Id<input type="text" name="User_Id" size="20">&nbsp;&nbsp; Password &nbsp;<input type="Password" name="Password" size="20"></p>
<p>First Name <input type="Text" name="First_Name" size="20">&nbsp; Last Name <input type="Text" name="Last_Name" size="20"></p>
<p>City <input type="Text" name="City" size="20">Address <input type="Text" name="Address" size="20">
<p>Occupation or School<input type="Text" name="Occupation_School" size="20">&nbsp;
Appt # <input type="Text" name="Apt_Num" size="20"><p>Province <input type="Text" name="Province" size="20">
Country <input type="Text" name="Country" size="20"></p>
<p>Cell Number <input type="Text" name="Cell_Num" size="20">
<p>Home Phone # <input type="Text" name="Home_Phone_Num" size="20">
Marital Status<input type="Text" name="Marital_Status" size="20"></p>
<p>Postal Code <input type="Text" name="Postal_Code" size="20">
<p>State<input type="Text" name="State" size="20">
<p>Email #1<input type="Text" name="Email_1" size="20">&nbsp; Email #2 <input type="Text" name="Email_2" size="20"><p>&nbsp;

<input type="Submit" value="Submit" onserverclick="registermember" runat="Server"></form>
</body>
</html>



<asp:label id="successful" runat="server" visible="false">
You Have successfully Registered!!
<p><a href="Home.aspx" >Back to home page to log in!</a></p>


</asp:label>
<asp:panel id="woops" runat="server" Visible="False">
Someone Has already taken that you User Id..Try another one plz.

</asp:panel>

PeOfEo
01-04-2004, 08:50 PM
Page_load
button_click
do it like that

Calmaris
01-04-2004, 10:17 PM
But how would I code that in reference to calling dotheregistermemeber ? I also realise that I don't think I need to make each sub in a seperate server script..Am I correct on this?

PeOfEo
01-04-2004, 11:00 PM
no, infact that should be causing errors.
dotheregistermember() will call it if it is not a event

CardboardHammer
01-07-2004, 05:27 PM
Here's an example of how to deal with procedures you want to use in various pages.

WHATEVER.vb

Module WHATEVER

Public Sub GetDefaultColors(ByRef colors() As Color)
Dim colors1(6) As Color
colors = colors1
colors(0) = Color.FromArgb(&HFF000000)
colors(1) = Color.FromArgb(&HFFFF6633)
colors(2) = Color.FromArgb(&HFF9900CC)
colors(3) = Color.FromArgb(&HFF99CCCC)
colors(4) = Color.FromArgb(&HFF006600)
colors(5) = Color.FromArgb(&HFFFFCC66)
End Sub

Public Function RemoveTags(ByVal strRaw As String) As String
'disable opening and closing tags...
strRaw = strRaw.Replace("<", "&lt")
strRaw = strRaw.Replace(">", "&gt")
Return strRaw
End Function
End Module



In any other page in the same assembly:

...

Dim arrColors() As Color
WHATEVER.GetDefaultColors(arrColors)

...

strSafePost = WHATEVER.RemoveTags(strRawPost )

...

CardboardHammer
01-07-2004, 05:30 PM
It's easier to keep a handle on your server side code if you put it in codebehind files instead of mixing it in with the HTML.

PeOfEo
01-07-2004, 08:17 PM
for things like a login form that is on every page I use code behinds, but when the code is being executed on just the one page I prefer to keep it on the page to be organised, lump it all together so I can deal with it all at once.

Calmaris
01-08-2004, 10:29 AM
Ok I figured it out. Thx alot guys for the help...what is code behind pages? Is that like a text file of code that the page can reference and run?

PeOfEo
01-08-2004, 04:31 PM
sort of. It is if you are using vb a .vb file, it is just a file with code in it and you import it on the page that is using the code. Somewhat like a class basically. The working code is not in the .aspx file it is in another file so therefore the code stays behind hence codebehind.

Calmaris
01-08-2004, 07:53 PM
Ok so for your login you would might make a script called login.vb and how you would call this script? Does it have to be in the same directory?

PeOfEo
01-08-2004, 09:11 PM
well, it has to be in the same virtual directory i believe. I keep all of mine in the same dir though. You just import it at the top basically.
<%@ Page Language="vb" Codebehind="WHATEVER.aspx.vb"%>

Calmaris
01-08-2004, 09:12 PM
so you can only have one? or call multiple pages from on page

PeOfEo
01-08-2004, 09:18 PM
multible pages can call the same codebehind and you can call more then one at a time I think, I have never needed too but I think you can call up as many as you like.

CardboardHammer
01-09-2004, 08:00 AM
(At least when developing with VS.NET) Each page has it's own codebehind file, samefilename.aspx.vb (when using VB.NET as the language) (.cp when using VB.NET as the language). The codebehind page is where you can stick the code for the corresponding aspx page. I don't know if multiple pages can use the same codebehind file, no situation has come up for me yet in which that would be "helpful".

To execute another page within the processing current page: use Server.Execute(otherpage[, optional textwriter to receive output of otherpage)

To call a function/sub in a Module: modulename.functionname([parameters])

Just curious... anyone else using VisualStudio.NET? If not, what do you use?

Calmaris
01-09-2004, 03:22 PM
lol I was using front page because I wasn't reading up on any articles for over a year...I've switched to webmatrix and I'm just trying that out.

PeOfEo
01-09-2004, 05:18 PM
I am using dreamweaver, its .net support is excellent.