By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,301 Members | 3,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,301 IT Pros & Developers. It's quick & easy.

calling functions in a script in .aspx page

P: n/a
Hello,
I created a Public class in .aspx.vb code behind file, now I want
to know can I call that functions in the class in the Scripts either client
side or server side in .aspx page. also I want to associate those functions
with the click of the button which is accesible in .aspx file. what should I
do.
Thank
you

Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Maybe you could provide an example?

It seems like all you have is this:

public class SomeClass
public function DoSomething() as String
return "hello"
end function
end class
If you want to call DoSomerthing, you can do:

dim sc as new SomeClass()
sc.DoSomething()
if you don't want to create an instance, make DoSomething() a shared
member...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"anoop" <an***@discussions.microsoft.com> wrote in message
news:D8**********************************@microsof t.com...
Hello,
I created a Public class in .aspx.vb code behind file, now I want
to know can I call that functions in the class in the Scripts either
client
side or server side in .aspx page. also I want to associate those
functions
with the click of the button which is accesible in .aspx file. what should
I
do.

Thank
you

Nov 19 '05 #2

P: n/a
Hello,
Yes, you are right. I have this kind of class and functions in it in
..aspx.vb code behind file. Now I want to ask you, can I call this function in
a VBscript in .aspx page in the Click event of a Button

the code is as follows

Public Class EmployeeData
Public Shared Sub Main()
Dim hiredate As DateTime = DateTime.Parse("4/27/98")
Dim newID As Integer = AddEmployee("D001", "Sales", "Smith", "John",
"Sales Representative", hiredate, 5, "smith.bmp")
Console.WriteLine("New Employee Added . EmployeeID=" & newID)
End Sub

Public Shared Function AddEmployee(ByVal department_id1 As String, ByVal
department_name1 As String, ByVal lastname1 As String, ByVal firstname1 As
String, ByVal title1 As String, ByVal hiredate1 As DateTime, ByVal reportsto1
As Integer, ByVal photofilepath1 As String) As Integer

Dim con As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection("Data Source=localhost;Integrated
Security=SSPI;Initial Catalog=Organization")
Dim addemp As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand("INSERT INTO Department
(Department_id,department_name,lastname,firstname, title,hiredate,reportsto,photo)
values(@departmentid,@departmentname,@lastname,@fi rstname,@title,@hiredate,@reportsto,0x0);SELECT
@identity=SCOPE_IDENTITY();SELECT @pointer=TEXTPTR(photo) from department
where department_id=@identity", con)
addemp.Parameters.Add("@departmentid", Data.SqlDbType.NChar,
4).Value = department_id1
addemp.Parameters.Add("@departmentname", Data.SqlDbType.NVarChar,
50).Value = department_name1
addemp.Parameters.Add("@lastname", Data.SqlDbType.NVarChar,
50).Value = lastname1
addemp.Parameters.Add("@firstname", Data.SqlDbType.NVarChar,
50).Value = firstname1
addemp.Parameters.Add("@title", Data.SqlDbType.NVarChar, 30).Value =
title1
addemp.Parameters.Add("@hiredate", Data.SqlDbType.DateTime).Value =
hiredate1
addemp.Parameters.Add("@reportsto", Data.SqlDbType.Int).Value =
reportsto1

Dim idparm As System.Data.SqlClient.SqlParameter =
addemp.Parameters.Add("@identity", Data.SqlDbType.Int)

idparm.Direction = Data.ParameterDirection.Output

Dim ptrparm As System.Data.SqlClient.SqlParameter =
addemp.Parameters.Add("@pointer", Data.SqlDbType.Binary, 16)

ptrparm.Direction = Data.ParameterDirection.Output

con.Open()

addemp.ExecuteNonQuery()

Dim newEmpID As Integer = CType(idparm.Value, Integer)

StorePhoto(photofilepath1, ptrparm.Value, con)
con.Close()

Return newEmpID
End Function

Public Shared Sub StorePhoto(ByVal filename As String, ByVal pointer As
Byte(), ByVal con As System.Data.SqlClient.SqlConnection)
Dim bufferLen As Integer = 128 ' The size of the "chunks" of the image

Dim appendToPhoto As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand("UPDATETEXT Department.Photo @pointer
@offset 0 @Bytes", con)
Dim ptrparm As System.Data.SqlClient.SqlParameter =
appendToPhoto.Parameters.Add("@pointer", Data.SqlDbType.Binary, 16)
ptrparm.Value = pointer
Dim photoparm As System.Data.SqlClient.SqlParameter =
appendToPhoto.Parameters.Add("@Bytes", Data.SqlDbType.Image, bufferLen)

Dim offsetParm As System.Data.SqlClient.SqlParameter =
appendToPhoto.Parameters.Add("@offset", Data.SqlDbType.Int)

offsetParm.Value = 0

''''''''''''''''''''''''''''''''''''
'' Read the image in and write it to the database 128 (bufferLen)
bytes at a time.
'' Tune bufferLen for best performance. Larger values write faster,
but
'' use more system resources.

Dim fs As System.IO.FileStream = New System.IO.FileStream(filename,
IO.FileMode.Open, IO.FileAccess.Read)

Dim br As System.IO.BinaryReader = New System.IO.BinaryReader(fs)

Dim buffer() As Byte = br.ReadBytes(bufferLen)

Dim offset_ctr As Integer = 0

Do While buffer.Length > 0
photoparm.Value = buffer
appendToPhoto.ExecuteNonQuery()
offset_ctr += bufferLen
offsetParm.Value = offset_ctr
buffer = br.ReadBytes(bufferLen)
Loop

br.Close()
fs.Close()
End Sub
End Class

"Karl Seguin" wrote:
Maybe you could provide an example?

It seems like all you have is this:

public class SomeClass
public function DoSomething() as String
return "hello"
end function
end class
If you want to call DoSomerthing, you can do:

dim sc as new SomeClass()
sc.DoSomething()
if you don't want to create an instance, make DoSomething() a shared
member...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"anoop" <an***@discussions.microsoft.com> wrote in message
news:D8**********************************@microsof t.com...
Hello,
I created a Public class in .aspx.vb code behind file, now I want
to know can I call that functions in the class in the Scripts either
client
side or server side in .aspx page. also I want to associate those
functions
with the click of the button which is accesible in .aspx file. what should
I
do.

Thank
you


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.