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

Send value to code behind sub procedure

Hello, I am trying to learn how to use Code Behind. Essentially, the
example of Block 1 and Block 2 are the same. The difference is that in
Block 1 I explicitly set the parameter value to "menu_help". When I open
the menu.aspx page and Call LoadMenu(), the value from the variable
"strMenu" will populate the html table.

However, with Block 2, I am sending the value "menu_help" using Call
LoadMenu("menu_help"). When I use the statement response.write(strMenu &
"from code behind<br>") in the Code Behind page, the variable information
for "strMenu" will show on the top of the page, but it won't show up in my
table.

Any help with this would be appreciated.

--
Thanks in advance,

Steven

************ Block 1 *************
Public Class DataConnection : Inherits Page

Public Sub LoadMenu()
'Declare Parameters for Stored Procedure
Dim spMenu As OleDb.OleDbDataReader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbCommand("sp_web_Search", cnnSearch)
Dim strRepeat As String
cmdMenu.CommandType = CommandType.StoredProcedure

'Menu Structure
prmMenu = cmdMenu.Parameters.Add("@strParm01", OleDbType.VarChar) :
prmMenu.Value = "FindWebMenu"
prmMenu = cmdMenu.Parameters.Add("@strParm02", OleDbType.VarChar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.ExecuteReader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenuTitle_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write(strMenu & "from code behind<br>")
End Sub
End Class
Menu.aspx
------------
<%@ Page Inherits="DataConnection" src="../../bin/cnnPricing.vb"
Explicit="True" Debug="True"%>

Sub Page_Load(Sender As Object, E As EventArgs)

If Not IsPostBack
Call LoadMenu()
response.write(strMenu & "hello Steven<br>")
....
End Sub

<div align="left" class="menu">
<table summary="" cellpadding="0" cellspacing="0" class="menu">
<tr><td><div align="left">&nbsp;</div></td></tr>
<tr><td><div align="left"><%= strMenu %></div></td></tr>
</table></div><br><br>
************ Block 2 *************
Public Class DataConnection : Inherits Page

Public Sub LoadMenu(strMenu As String)
'Declare Parameters for Stored Procedure
Dim spMenu As OleDb.OleDbDataReader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbCommand("sp_web_Search", cnnSearch)
Dim strRepeat As String
cmdMenu.CommandType = CommandType.StoredProcedure

'Menu Structure
prmMenu = cmdMenu.Parameters.Add("@strParm01", OleDbType.VarChar) :
prmMenu.Value = "FindWebMenu"
prmMenu = cmdMenu.Parameters.Add("@strParm02", OleDbType.VarChar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.ExecuteReader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenuTitle_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write(strMenu & "from code behind<br>")
End Sub
End Class

Menu.aspx
-----------
<%@ Page Inherits="DataConnection" src="../../bin/cnnPricing.vb"
Explicit="True" Debug="True"%>

Sub Page_Load(Sender As Object, E As EventArgs)

If Not IsPostBack
Call LoadConnection()
Call LoadMenu("menu_help")
....
End Sub

<div align="left" class="menu">
<table summary="" cellpadding="0" cellspacing="0" class="menu">
<tr><td><div align="left">&nbsp;</div></td></tr>
<tr><td><div align="left"><%= strMenu %></div></td></tr>
</table></div><br><br>

Nov 18 '05 #1
2 1951
I'm a little confused, but the right way to do it is not to use
response.write or <%= %>, but instead to use server controls:

<table summary="" cellpadding="0" cellspacing="0" class="menu">
<tr><td><div align="left">&nbsp;</div></td></tr>
<tr><td><div align="left"><ASP:LITERAL ID="STRMENU" RUNAT="SERVER"
/></div></td></tr>
</table>

and in your codebehind declare that control
Protected strMenu as System.Web.UI.WebControl.Literal

and in your LoadMenu() do:
dim str as string
...
while read
str = str & sp_menu("....")
end
strMenu.Text = str

Karl

"Steven K" <sk****@troop.com> wrote in message
news:Og**************@TK2MSFTNGP11.phx.gbl...
Hello, I am trying to learn how to use Code Behind. Essentially, the
example of Block 1 and Block 2 are the same. The difference is that in
Block 1 I explicitly set the parameter value to "menu_help". When I open
the menu.aspx page and Call LoadMenu(), the value from the variable
"strMenu" will populate the html table.

However, with Block 2, I am sending the value "menu_help" using Call
LoadMenu("menu_help"). When I use the statement response.write(strMenu &
"from code behind<br>") in the Code Behind page, the variable information
for "strMenu" will show on the top of the page, but it won't show up in my
table.

Any help with this would be appreciated.

--
Thanks in advance,

Steven

************ Block 1 *************
Public Class DataConnection : Inherits Page

Public Sub LoadMenu()
'Declare Parameters for Stored Procedure
Dim spMenu As OleDb.OleDbDataReader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbCommand("sp_web_Search", cnnSearch)
Dim strRepeat As String
cmdMenu.CommandType = CommandType.StoredProcedure

'Menu Structure
prmMenu = cmdMenu.Parameters.Add("@strParm01", OleDbType.VarChar) :
prmMenu.Value = "FindWebMenu"
prmMenu = cmdMenu.Parameters.Add("@strParm02", OleDbType.VarChar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.ExecuteReader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenuTitle_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write(strMenu & "from code behind<br>")
End Sub
End Class
Menu.aspx
------------
<%@ Page Inherits="DataConnection" src="../../bin/cnnPricing.vb"
Explicit="True" Debug="True"%>

Sub Page_Load(Sender As Object, E As EventArgs)

If Not IsPostBack
Call LoadMenu()
response.write(strMenu & "hello Steven<br>")
...
End Sub

<div align="left" class="menu">
<table summary="" cellpadding="0" cellspacing="0" class="menu">
<tr><td><div align="left">&nbsp;</div></td></tr>
<tr><td><div align="left"><%= strMenu %></div></td></tr>
</table></div><br><br>
************ Block 2 *************
Public Class DataConnection : Inherits Page

Public Sub LoadMenu(strMenu As String)
'Declare Parameters for Stored Procedure
Dim spMenu As OleDb.OleDbDataReader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbCommand("sp_web_Search", cnnSearch)
Dim strRepeat As String
cmdMenu.CommandType = CommandType.StoredProcedure

'Menu Structure
prmMenu = cmdMenu.Parameters.Add("@strParm01", OleDbType.VarChar) :
prmMenu.Value = "FindWebMenu"
prmMenu = cmdMenu.Parameters.Add("@strParm02", OleDbType.VarChar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.ExecuteReader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenuTitle_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write(strMenu & "from code behind<br>")
End Sub
End Class

Menu.aspx
-----------
<%@ Page Inherits="DataConnection" src="../../bin/cnnPricing.vb"
Explicit="True" Debug="True"%>

Sub Page_Load(Sender As Object, E As EventArgs)

If Not IsPostBack
Call LoadConnection()
Call LoadMenu("menu_help")
...
End Sub

<div align="left" class="menu">
<table summary="" cellpadding="0" cellspacing="0" class="menu">
<tr><td><div align="left">&nbsp;</div></td></tr>
<tr><td><div align="left"><%= strMenu %></div></td></tr>
</table></div><br><br>

Nov 18 '05 #2
What about using "server-side" tables?
something like this:
Dim row As TableRow = New TableRow

Dim c As TableCell = New TableCell

c.Text = LoadMenu() 'of course loadmenu() returns a string

row.Cells.Add(c)

Table1.Rows.Add(row)

take a look at:
http://samples.gotdotnet.com/quickst...e1.aspx&font=3

--
Saber S.
http://maghalat.com (Persian)
"Steven K" <sk****@troop.com> wrote in message
news:Og**************@TK2MSFTNGP11.phx.gbl...
Hello, I am trying to learn how to use Code Behind. Essentially, the
example of Block 1 and Block 2 are the same. The difference is that in
Block 1 I explicitly set the parameter value to "menu_help". When I open
the menu.aspx page and Call LoadMenu(), the value from the variable
"strMenu" will populate the html table.

However, with Block 2, I am sending the value "menu_help" using Call
LoadMenu("menu_help"). When I use the statement response.write(strMenu &
"from code behind<br>") in the Code Behind page, the variable information
for "strMenu" will show on the top of the page, but it won't show up in my
table.

Any help with this would be appreciated.

--
Thanks in advance,

Steven

************ Block 1 *************
Public Class DataConnection : Inherits Page

Public Sub LoadMenu()
'Declare Parameters for Stored Procedure
Dim spMenu As OleDb.OleDbDataReader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbCommand("sp_web_Search", cnnSearch)
Dim strRepeat As String
cmdMenu.CommandType = CommandType.StoredProcedure

'Menu Structure
prmMenu = cmdMenu.Parameters.Add("@strParm01", OleDbType.VarChar) :
prmMenu.Value = "FindWebMenu"
prmMenu = cmdMenu.Parameters.Add("@strParm02", OleDbType.VarChar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.ExecuteReader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenuTitle_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write(strMenu & "from code behind<br>")
End Sub
End Class
Menu.aspx
------------
<%@ Page Inherits="DataConnection" src="../../bin/cnnPricing.vb"
Explicit="True" Debug="True"%>

Sub Page_Load(Sender As Object, E As EventArgs)

If Not IsPostBack
Call LoadMenu()
response.write(strMenu & "hello Steven<br>")
...
End Sub

<div align="left" class="menu">
<table summary="" cellpadding="0" cellspacing="0" class="menu">
<tr><td><div align="left">&nbsp;</div></td></tr>
<tr><td><div align="left"><%= strMenu %></div></td></tr>
</table></div><br><br>
************ Block 2 *************
Public Class DataConnection : Inherits Page

Public Sub LoadMenu(strMenu As String)
'Declare Parameters for Stored Procedure
Dim spMenu As OleDb.OleDbDataReader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbCommand("sp_web_Search", cnnSearch)
Dim strRepeat As String
cmdMenu.CommandType = CommandType.StoredProcedure

'Menu Structure
prmMenu = cmdMenu.Parameters.Add("@strParm01", OleDbType.VarChar) :
prmMenu.Value = "FindWebMenu"
prmMenu = cmdMenu.Parameters.Add("@strParm02", OleDbType.VarChar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.ExecuteReader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenuTitle_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write(strMenu & "from code behind<br>")
End Sub
End Class

Menu.aspx
-----------
<%@ Page Inherits="DataConnection" src="../../bin/cnnPricing.vb"
Explicit="True" Debug="True"%>

Sub Page_Load(Sender As Object, E As EventArgs)

If Not IsPostBack
Call LoadConnection()
Call LoadMenu("menu_help")
...
End Sub

<div align="left" class="menu">
<table summary="" cellpadding="0" cellspacing="0" class="menu">
<tr><td><div align="left">&nbsp;</div></td></tr>
<tr><td><div align="left"><%= strMenu %></div></td></tr>
</table></div><br><br>

Nov 18 '05 #3

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

Similar topics

3
by: Vipul Pathak | last post by:
Hello Friends ! I have the Following Code, that Executes a Stored Procedure and Attempt to read a Returned Integer Value from the StoredProc. But It gives Error ... ADODB.Command (0x800A0BB9)...
1
by: a | last post by:
how to send an xml dataset to a Stored Procedure in mssql I have an xml file that I read into a dataset. and I'm trying to use a stored procedure (see SPROC #1 below) that inserts this xml...
11
by: Tim Smallwood | last post by:
Hi, I have an Access project that I use to allow a client to hit an SQL server at my host. This project has several forms that are used to udpate tables, etc, but I'd also like to be able to...
1
by: Pat | last post by:
All, What I want to do: ******************* Click on a hyperlink in the last column in a datagrid, have it grab a value in the fourth column in the same row and send it to the codehind into a...
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
7
by: Gene | last post by:
I have a number of aspx pages on which a single user control appears. All of the aspx pages and the user control make user of code-behind modules. I need for logic in the user control's code-behind...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
4
by: raghav | last post by:
Hi all I am having a SP which is returning a value......Now I have to store that value in session...I saw some examples in msdn lib ----> string Name=string.Empty; Session=Name.ToString(); ...
2
by: Piotrek \Alchemik\ | last post by:
Hello, i have small problem - i have dropdownlist, which is populated from database by stored procedure. I had autopostback attached to this list. I'm using this as a parameter to another stored...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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.