473,796 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.OleDbData Reader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbComm and("sp_web_Sea rch", cnnSearch)
Dim strRepeat As String
cmdMenu.Command Type = CommandType.Sto redProcedure

'Menu Structure
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm01", OleDbType.VarCh ar) :
prmMenu.Value = "FindWebMen u"
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm02", OleDbType.VarCh ar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.Execute Reader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenu Title_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write( strMenu & "from code behind<br>")
End Sub
End Class
Menu.aspx
------------
<%@ Page Inherits="DataC onnection" src="../../bin/cnnPricing.vb"
Explicit="True" Debug="True"%>

Sub Page_Load(Sende r 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">&n bsp;</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(strMen u As String)
'Declare Parameters for Stored Procedure
Dim spMenu As OleDb.OleDbData Reader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbComm and("sp_web_Sea rch", cnnSearch)
Dim strRepeat As String
cmdMenu.Command Type = CommandType.Sto redProcedure

'Menu Structure
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm01", OleDbType.VarCh ar) :
prmMenu.Value = "FindWebMen u"
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm02", OleDbType.VarCh ar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.Execute Reader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenu Title_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write( strMenu & "from code behind<br>")
End Sub
End Class

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

Sub Page_Load(Sende r 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">&n bsp;</div></td></tr>
<tr><td><div align="left"><% = strMenu %></div></td></tr>
</table></div><br><br>

Nov 18 '05 #1
2 1974
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">&n bsp;</div></td></tr>
<tr><td><div align="left"><A SP:LITERAL ID="STRMENU" RUNAT="SERVER"
/></div></td></tr>
</table>

and in your codebehind declare that control
Protected strMenu as System.Web.UI.W ebControl.Liter al

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

Karl

"Steven K" <sk****@troop.c om> wrote in message
news:Og******** ******@TK2MSFTN GP11.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.OleDbData Reader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbComm and("sp_web_Sea rch", cnnSearch)
Dim strRepeat As String
cmdMenu.Command Type = CommandType.Sto redProcedure

'Menu Structure
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm01", OleDbType.VarCh ar) :
prmMenu.Value = "FindWebMen u"
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm02", OleDbType.VarCh ar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.Execute Reader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenu Title_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write( strMenu & "from code behind<br>")
End Sub
End Class
Menu.aspx
------------
<%@ Page Inherits="DataC onnection" src="../../bin/cnnPricing.vb"
Explicit="True" Debug="True"%>

Sub Page_Load(Sende r 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">&n bsp;</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(strMen u As String)
'Declare Parameters for Stored Procedure
Dim spMenu As OleDb.OleDbData Reader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbComm and("sp_web_Sea rch", cnnSearch)
Dim strRepeat As String
cmdMenu.Command Type = CommandType.Sto redProcedure

'Menu Structure
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm01", OleDbType.VarCh ar) :
prmMenu.Value = "FindWebMen u"
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm02", OleDbType.VarCh ar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.Execute Reader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenu Title_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write( strMenu & "from code behind<br>")
End Sub
End Class

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

Sub Page_Load(Sende r 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">&n bsp;</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.c om> wrote in message
news:Og******** ******@TK2MSFTN GP11.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.OleDbData Reader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbComm and("sp_web_Sea rch", cnnSearch)
Dim strRepeat As String
cmdMenu.Command Type = CommandType.Sto redProcedure

'Menu Structure
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm01", OleDbType.VarCh ar) :
prmMenu.Value = "FindWebMen u"
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm02", OleDbType.VarCh ar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.Execute Reader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenu Title_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write( strMenu & "from code behind<br>")
End Sub
End Class
Menu.aspx
------------
<%@ Page Inherits="DataC onnection" src="../../bin/cnnPricing.vb"
Explicit="True" Debug="True"%>

Sub Page_Load(Sende r 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">&n bsp;</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(strMen u As String)
'Declare Parameters for Stored Procedure
Dim spMenu As OleDb.OleDbData Reader
Dim prmMenu As OleDbParameter
Dim cmdMenu As New OleDb.OleDbComm and("sp_web_Sea rch", cnnSearch)
Dim strRepeat As String
cmdMenu.Command Type = CommandType.Sto redProcedure

'Menu Structure
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm01", OleDbType.VarCh ar) :
prmMenu.Value = "FindWebMen u"
prmMenu = cmdMenu.Paramet ers.Add("@strPa rm02", OleDbType.VarCh ar) :
prmMenu.Value = "menu_help"
spMenu = cmdMenu.Execute Reader()
Do While spMenu.Read
strMenu = strMenu & spMenu("WebMenu Title_ID")
Loop
spMenu.Close() : spMenu = Nothing
response.write( strMenu & "from code behind<br>")
End Sub
End Class

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

Sub Page_Load(Sende r 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">&n bsp;</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
22930
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) Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. /C4U/DBOutputParameterTest.asp, line 25
1
4930
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 dataset into an sql table via OpenXML. Nothing gets inserted into the sql table except nulls, so I think that perhaps I'm not actually sending the (xml) dataset to the SPROC. The code below fails on this line: sqlCommand1.ExecuteNonQuery();
11
5037
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 include the ability to allow my client to send an email to everyone that has subscribed to our web site by going to the table that contains the names and email addy's and then loop thru the same and send an email to them all by appending their...
1
6550
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 function that will then put the value into a query and send it off the database.... and do some stuff with the return. What I have so far:
7
7746
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 which will be used to query sql server to repopulate the datagrid in the user control. I also wrapped the user control in a panel element so I could position it on the page. I'm clueless on how to get started with this.
7
2427
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 to read the current value of a variable in the hosting aspx page's code-behind. How is this accomplished? Thanks.
17
2721
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 know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
4
2066
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(); But in my case return value is ID ...and it has not been declared in C#
2
1632
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 procedure. So, when i was using asp:SqlDataSource and bind to him values from this dropdownlist everything was ok. But when i'm doing this in code behind using SqlCommand and trying to get value from this dropdownlist sensor =...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10244
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10201
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7558
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.