Re: Public variable not seen by all controls on a Page
- From: "John Kotuby" <JohnKotuby@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 12 Dec 2007 17:30:43 -0500
Thanks Scott,
You have been really helpful and thanks for not torching me on a such a
fundamental question.
VB allows for case insensitivity, but it is always good practice to practice
using proper case, as I am sometimes forced into writing Javascript routines
to attain a certain result. I am getting the sense that VB.NET will soon be
a thing of the past...even with assurances for Microsoft that it will
continue support.
"Scott Roberts" <sroberts@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:uoerKuQPIHA.5980@xxxxxxxxxxxxxxxxxxxxxxx
"quickAdd" is public, but it's not "Global". It's still a property of the
User Control, so you must reference it through the User Control. Try this:
<% If Not PCSavedSearches1.quickAdd = "Y" Then %>
Also note that you have the property declared as "quickAdd" but you are
referencing "quickadd". I'm not familiar with VB, but in C# property names
are case-sensitive.
Sorry for the obvious lack of details. I am using VB.NET and declaring a
simple string variable named "quickAdd".
------------------------------------
Partial Class Controls_User_PCSavedSearches
Inherits System.Web.UI.UserControl
Public quickAdd
End Sub
----------------------------------------
The User control that belongs to the code-behind class is added to the
main ASPX page.
------------------------------------------
<%@ Page Language="VB" MasterPageFile="~/SearchPage.master"
AutoEventWireup="false" EnableSessionState="True"
CodeFile="chooseSearch.aspx.vb" Inherits="Search_chooseSearch"
title="Saved Search Criteria" %>
<%@ MasterType VirtualPath="~/SearchPage.master" %>
<%@ Register Src="../Controls/User/PCSavedSearches.ascx"
TagName="PCSavedSearches"
TagPrefix="uc2" %>
<%@ Register Src="../Controls/User/CreateQuickSearchBar.ascx"
TagName="CreateQuickSearchBar"
TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content1"
Runat="Server">
<% If Not quickadd = "Y" Then%>
<uc1:CreateQuickSearchBar ID="CreateQuickSearchBar1" runat="server" />
<% End If%>
<uc2:PCSavedSearches ID="PCSavedSearches1" runat="server" />
<input type="hidden" name="txtDeckName" id="txtDeckName"
value="<%=strDeckName %>" />
</asp:Content>
--------------------------------------------
I make reference to the variable and of course the compiler tells me it
is not declared, even though the Control is registered and is part of the
ASPX page. I guess I was wrong in thinking that if a simple string
variable is declared Public, even within a class, that it might be
viewable outside the class. I am wondering if I create a Public Property
named QuickAdd and feed it the contents of the variable quickAdd that I
can do something like...
<% If Not Controls_User_PCSavedSearches.QuickAdd = "Y" Then%>
But I would most likely need to instantiate the class before referring to
it.
Sorry to bother you all with such trivial stuff.
"Peter Bromberg [C# MVP]" <pbromberg@xxxxxxxxxxxxxxxxxxxx> wrote in
message news:8B0E54D8-7108-4A87-87B4-1446A6E496C3@xxxxxxxxxxxxxxxx
You don't specify in your post how and with what code you are declaring
this
variable. If your field is a public field in the UserControl or a public
property, then from anywhere in the Page you should be able to use
FindControl method to get a reference to your UserControl and access the
property and its value.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"John Kotuby" wrote:
Hi all,
In ASP.NET 2.0 I have some pages that are composed of a Master Page and
several User controls. In one of the pages I declare a Public variable
within the code-behind of a User Control on the page.
I populate the variable during the Page_Load event of the User Control.
When I reference the variable in another part of the page, specifically
in
Page_Load of the main ASPX or even Page_PreRender VS tells me the
variable
is not declared.
Is there a place in the page where I can declare a variable (maybe
using
something other than Public for the declaration?) so that it can be
seen and
referenced by all members of the page, but Only within the page itself?
Thanks...
.
- References:
- Public variable not seen by all controls on a Page
- From: John Kotuby
- Re: Public variable not seen by all controls on a Page
- From: John Kotuby
- Re: Public variable not seen by all controls on a Page
- From: Scott Roberts
- Public variable not seen by all controls on a Page
- Prev by Date: Re: PHP's output buffer and ASP.NET's Response.OutputStream
- Next by Date: Make DropDownList fire a clientside Javascript function?
- Previous by thread: Re: Public variable not seen by all controls on a Page
- Next by thread: PHP's output buffer and ASP.NET's Response.OutputStream
- Index(es):
Relevant Pages
|
Loading