473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

calling functions in a script in .aspx page

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
2 1874
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: JCO | last post by:
I have several JavaScripts in a web page. Each script is in an individual file with extension .js. I want to know if it is possible to put all functions in one single page. If so, how do I call...
5
by: benc | last post by:
Hi Can some good soul help on this. I need to call jscript functions from C#. I have hosted a web control and displayed an html page successfully, but just can't find a way to call jscript...
2
by: Fred Armitage | last post by:
I have a fairly complex application written using a vb code-behind dll. However, I'd like to write one particular aspx page utilising in-line code so that it can easily be modified as needed by the...
5
by: Mark Fox | last post by:
Hello, I have a page DoBatchWork.aspx that my web host's cron requests periodically. It currently calls another web page that does some batch processing. The code I am currently using in...
3
by: Dustin II. | last post by:
Hi, I have an ASP.NET solution, and the ASPX page I have a form , I want to copy some of the data from that form to the clipboard, I am using the below script the script works fine when I use a...
2
by: shaun duke | last post by:
I have been researching this over the last two days without success. I have a number of ultility functions that I want to make available to all pages. The pages will all be using code behind so...
6
by: johnf401 | last post by:
I've got a VB .NET Web application that has several frames (for discussion sake, let's call them Form1.aspx and Form2.aspx). I want to be able to call a code module in Form2.aspx.vb from code...
2
by: mikepolitowski | last post by:
Hi folks, I am have been trying to solve this problem for quite some time now and would appreciate any advice. I have been trying to call a code-behind function that is defined in my aspx.cs...
5
by: Newbie Coder | last post by:
Hello all I have 3 functions in a javacrip file (MyScript.js), which is added to an ASP.NET 2.0 project 1) no right-click 2) no select text (copy...) 3) History.Back()' How do I call...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.