473,395 Members | 2,006 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,395 software developers and data experts.

Can't get value from one function to another in Aspx page

I'm trying to check for "No Records Found" in a repeater list control,
but my 'numrows' variable cannot be seen by the function CheckNoR ,
even tho it's public (?)

<script runat="server">
'Handle page load event
public Sub Page_Load(Sender As Object, E As EventArgs)

Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataAdapter
dim MyDataset As DataSet
dim MyTable As DataTable
dim numrows As Integer
dim sqlstr As String
sqlstr = "SELECT company,city from customers "

MyConnection = New SqlConnection("Data Source=dbase.net;Initial
Catalog=mydb;User Id=myuser;Password=mypwd;")

MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Create a Command object with the SQL statement.
MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Fill a DataSet with data returned from the database.
MyDataset = New DataSet
MyCommand.Fill(MyDataset)

' Create a new DataTable object and assign to it
' the new table in the Tables collection.
MyTable = New DataTable
MyTable = MyDataset.Tables(0)

''''tie it to my repeater control
dr.DataSource = MyTable
dr.DataBind()
MyConnection.Close

End Sub

</script>
<script runat="server">
function checkNoR(ByVal as String)
numrows = MyTable.Rows.Count
If numrows = 0 then
Response.Write("<p>No records.</p>")
End If
end function
</script>

Jul 10 '07 #1
4 2223
mister-Ed wrote:
I'm trying to check for "No Records Found" in a repeater list control,
but my 'numrows' variable cannot be seen by the function CheckNoR ,
even tho it's public (?)

<script runat="server">
'Handle page load event
public Sub Page_Load(Sender As Object, E As EventArgs)

Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataAdapter
dim MyDataset As DataSet
dim MyTable As DataTable
MyTable is a local variable in the Page_Load method.
dim numrows As Integer
numrows is a local variable in the Page_Load method.
dim sqlstr As String
sqlstr = "SELECT company,city from customers "

MyConnection = New SqlConnection("Data Source=dbase.net;Initial
Catalog=mydb;User Id=myuser;Password=mypwd;")

MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Create a Command object with the SQL statement.
MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Fill a DataSet with data returned from the database.
MyDataset = New DataSet
MyCommand.Fill(MyDataset)

' Create a new DataTable object and assign to it
' the new table in the Tables collection.
MyTable = New DataTable
MyTable = MyDataset.Tables(0)

''''tie it to my repeater control
dr.DataSource = MyTable
dr.DataBind()
MyConnection.Close

End Sub

</script>
<script runat="server">
function checkNoR(ByVal as String)
numrows = MyTable.Rows.Count
Neither numrows nor MyTable exist outside the Page_Load method.
If numrows = 0 then
Response.Write("<p>No records.</p>")
End If
end function
</script>

--
Göran Andersson
_____
http://www.guffa.com
Jul 10 '07 #2
Neither numrows nor MyTable exist outside the Page_Load method.
Well, yes, I need to find a way to make them available in the CheckNoR
function without having to re-declare all the ADO objects and
'numrows' and re-assign values
thanx
Ed

Jul 10 '07 #3
mister-Ed wrote:
>Neither numrows nor MyTable exist outside the Page_Load method.

Well, yes, I need to find a way to make them available in the CheckNoR
function without having to re-declare all the ADO objects and
'numrows' and re-assign values
thanx
Ed
Declare them as member variables in the page class.

--
Göran Andersson
_____
http://www.guffa.com
Jul 10 '07 #4
On Jul 10, 9:09 am, Göran Andersson <g...@guffa.comwrote:
mister-Ed wrote:
Neither numrows nor MyTable exist outside the Page_Load method.
Well, yes, I need to find a way to make them available in the CheckNoR
function without having to re-declare all the ADO objects and
'numrows' and re-assign values
thanx
Ed

Declare them as member variables in the page class.

--
Göran Andersson
_____http://www.guffa.com

Thanks for reply and help. ARE there any tutorials/helpful links that
explains how to do this?

Jul 10 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chung | last post by:
Hi all, I have used the following code for doing the form submission. I don't think this is a right way to submit a from to a new aspx page because I need to add a dummy form in between. Could...
4
by: tom | last post by:
Hi Experts, I want to pass the selectedDate value from my calender form to another web form or a web user control. Could you please show me how to do this? Thanks in advance.
1
by: vinuta | last post by:
I have three vb classes. First one has a variable whose value i want to use in a function in third vb class which is called by the second vb class. e:g; first.aspx.vb second.aspx.vb third.vb...
5
by: Steven | last post by:
I'm using C# as code-behind for my aspx pages. How can I bind pages.. so that both the pages can use the functions, variables, controls .. between each other. eg., if I declare function scope()...
17
by: Rabbit | last post by:
Hi, On my 1st page, i have a function which gets a new ID value and need to transfer to another immediately. which I want to get in 2nd page using Request.form("txtID"), but doesn't work, the...
1
by: Mike Hofer | last post by:
I really need some help, and I'd appreciate any that you folks can provide. The ASP.NET application in question uses version 1.1 of the .NET Framework. All of the pages use a common base class...
1
by: pbd22 | last post by:
hi. i have been posting this here and elsewhere a lot and can't seem to get resolution on this problem. i have been trying to upload files using a hidden iframe to a asp.net/vb.net form. the...
16
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString...
0
by: omer013 | last post by:
Hi; I have an aspx page with a WebMethod to redirect the user to another page. The Default.aspx.cs is; public partial class _Default : System.Web.UI.Page { public static void...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.