Send value to code behind sub procedure

S

Steven K

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>
 
K

Karl

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top