I'm trying to set up a user control and change some values from the aspx
page, but I keep running into trouble. What I really would like to do is be
able to set a Label.Text in the user control from an aspx page.
If I open up a static method to set the Label in the code-behind of the user
control(uc), then the code in the uc doesn't recognize that the label exists
(only if the method is a static (shared) method). If I set up a private
method, then the aspx page can't access the method, but then the uc does
recognize that the conrtol is there. Catch 22.
The old ASP way, I would just set the variable to the correct value on the
ASP page and the include would write it in a <%=SOMEVAR%>. How do I
accomplish this with user controls, or in this case, should I just resort to
an include file?
Andrea 4 1362
Your second paragraph made my head hurt from trying to figure out what it
meant, so I'm just going to ignore that. Let's just stick to changing a
property of a User Control in a WebForm. This is all object-oriented, so
let's start by talking about what these Controls are, which is objects. The
Page is an object/class, as is the WebForm contained in the Page, as is any
User Control that you add to a WebForm. Because these are all classes, there
are hidden (protected/private) and accessible (public) members. In order to
access a property or field in the User Control, you must have a public
property or field in the User Control which exposes it (makes it accessible
to other classes).
Next, you need to grab a reference to the User Control to set that
property/field's value. This can be done using the Control.FindCon trol()
method, which takes a string as its argument, representing the id property
of the Control being sought. The FindControl() Method searches the Controls
Collection of a Control and finds the Child Control that has the id that is
passed, and returns a reference to that Control. It works only on the
immediate Children of a Control, so you need to identify the Control that
contains it. Most likely, this will be the WebForm (not the Page).
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message
news:#R******** ******@TK2MSFTN GP10.phx.gbl... I'm trying to set up a user control and change some values from the aspx page, but I keep running into trouble. What I really would like to do is
be able to set a Label.Text in the user control from an aspx page.
If I open up a static method to set the Label in the code-behind of the
user control(uc), then the code in the uc doesn't recognize that the label
exists (only if the method is a static (shared) method). If I set up a private method, then the aspx page can't access the method, but then the uc does recognize that the conrtol is there. Catch 22.
The old ASP way, I would just set the variable to the correct value on the ASP page and the include would write it in a <%=SOMEVAR%>. How do I accomplish this with user controls, or in this case, should I just resort
to an include file?
Andrea
Ok, at first I didn't understand your explaination, but a search on the
FindControl() method in the MSDN Lib got me thinking and experimenting, now
I understand.
THANKS! I am now able to do what I need! :-))
Andrea
"Kevin Spencer" <ke***@takempis .com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Your second paragraph made my head hurt from trying to figure out what it meant, so I'm just going to ignore that. Let's just stick to changing a property of a User Control in a WebForm. This is all object-oriented, so let's start by talking about what these Controls are, which is objects.
The Page is an object/class, as is the WebForm contained in the Page, as is
any User Control that you add to a WebForm. Because these are all classes,
there are hidden (protected/private) and accessible (public) members. In order
to access a property or field in the User Control, you must have a public property or field in the User Control which exposes it (makes it
accessible to other classes).
Next, you need to grab a reference to the User Control to set that property/field's value. This can be done using the Control.FindCon trol() method, which takes a string as its argument, representing the id property of the Control being sought. The FindControl() Method searches the
Controls Collection of a Control and finds the Child Control that has the id that
is passed, and returns a reference to that Control. It works only on the immediate Children of a Control, so you need to identify the Control that contains it. Most likely, this will be the WebForm (not the Page).
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Big things are made up of lots of little things.
"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message news:#R******** ******@TK2MSFTN GP10.phx.gbl... I'm trying to set up a user control and change some values from the aspx page, but I keep running into trouble. What I really would like to do
is be able to set a Label.Text in the user control from an aspx page.
If I open up a static method to set the Label in the code-behind of the user control(uc), then the code in the uc doesn't recognize that the label exists (only if the method is a static (shared) method). If I set up a private method, then the aspx page can't access the method, but then the uc does recognize that the conrtol is there. Catch 22.
The old ASP way, I would just set the variable to the correct value on
the ASP page and the include would write it in a <%=SOMEVAR%>. How do I accomplish this with user controls, or in this case, should I just
resort to an include file?
Andrea
Ok, another problem, FindControl only seems to work on Web Controls and not
HTML controls.... Am I missing something?
Andrea
"Kevin Spencer" <ke***@takempis .com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Your second paragraph made my head hurt from trying to figure out what it meant, so I'm just going to ignore that. Let's just stick to changing a property of a User Control in a WebForm. This is all object-oriented, so let's start by talking about what these Controls are, which is objects.
The Page is an object/class, as is the WebForm contained in the Page, as is
any User Control that you add to a WebForm. Because these are all classes,
there are hidden (protected/private) and accessible (public) members. In order
to access a property or field in the User Control, you must have a public property or field in the User Control which exposes it (makes it
accessible to other classes).
Next, you need to grab a reference to the User Control to set that property/field's value. This can be done using the Control.FindCon trol() method, which takes a string as its argument, representing the id property of the Control being sought. The FindControl() Method searches the
Controls Collection of a Control and finds the Child Control that has the id that
is passed, and returns a reference to that Control. It works only on the immediate Children of a Control, so you need to identify the Control that contains it. Most likely, this will be the WebForm (not the Page).
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Big things are made up of lots of little things.
"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message news:#R******** ******@TK2MSFTN GP10.phx.gbl... I'm trying to set up a user control and change some values from the aspx page, but I keep running into trouble. What I really would like to do
is be able to set a Label.Text in the user control from an aspx page.
If I open up a static method to set the Label in the code-behind of the user control(uc), then the code in the uc doesn't recognize that the label exists (only if the method is a static (shared) method). If I set up a private method, then the aspx page can't access the method, but then the uc does recognize that the conrtol is there. Catch 22.
The old ASP way, I would just set the variable to the correct value on
the ASP page and the include would write it in a <%=SOMEVAR%>. How do I accomplish this with user controls, or in this case, should I just
resort to an include file?
Andrea
Ok, another problem, FindControl only seems to work on Web Controls and not
HTML controls.... Am I missing something?
Andrea
"Kevin Spencer" <ke***@takempis .com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Your second paragraph made my head hurt from trying to figure out what it meant, so I'm just going to ignore that. Let's just stick to changing a property of a User Control in a WebForm. This is all object-oriented, so let's start by talking about what these Controls are, which is objects.
The Page is an object/class, as is the WebForm contained in the Page, as is
any User Control that you add to a WebForm. Because these are all classes,
there are hidden (protected/private) and accessible (public) members. In order
to access a property or field in the User Control, you must have a public property or field in the User Control which exposes it (makes it
accessible to other classes).
Next, you need to grab a reference to the User Control to set that property/field's value. This can be done using the Control.FindCon trol() method, which takes a string as its argument, representing the id property of the Control being sought. The FindControl() Method searches the
Controls Collection of a Control and finds the Child Control that has the id that
is passed, and returns a reference to that Control. It works only on the immediate Children of a Control, so you need to identify the Control that contains it. Most likely, this will be the WebForm (not the Page).
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Big things are made up of lots of little things.
"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message news:#R******** ******@TK2MSFTN GP10.phx.gbl... I'm trying to set up a user control and change some values from the aspx page, but I keep running into trouble. What I really would like to do
is be able to set a Label.Text in the user control from an aspx page.
If I open up a static method to set the Label in the code-behind of the user control(uc), then the code in the uc doesn't recognize that the label exists (only if the method is a static (shared) method). If I set up a private method, then the aspx page can't access the method, but then the uc does recognize that the conrtol is there. Catch 22.
The old ASP way, I would just set the variable to the correct value on
the ASP page and the include would write it in a <%=SOMEVAR%>. How do I accomplish this with user controls, or in this case, should I just
resort to an include file?
Andrea
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Seth Guard |
last post by:
(Sorry for the cross-post, but no one responded to my other thread.)
When developing a web page in VS.Net, I see everything in WYSIWYG
format. And when I am creating a User Control, I see that drawn the
same way.
However, when I drag the User Control onto my main page, I see a gray
box where the User Control should be. (I was expecting to see my User
Control actually *rendered* on the Design screen, similar to how
FrontPage renders...
|
by: BBM |
last post by:
Hi,
I have been developing with C# User Controls and occasionally have a problem
where I "lose" a control from the design surface of the User Control. The
controls that I am using to build my User Controls are themselves custom
controls.
Occasionally, when I change something in either the User Control and/or one
of the custom controls that are on it and recompile, when I go to the
"Visual" design surface of the User Control, the...
|
by: Murphy |
last post by:
I have a number of pages that include basic html such as "About" and I have
delegated the upkeep of these pages to various staff.
I am concerned about having the staff edit the aspx file directly as there
is more than just the html page content in there and I don't want it stuffed
up. Until now I have put the content in an aspx that is placed on the aspx
however as the content is mere html should I simply put it in a text file
and use an...
|
by: Rajani |
last post by:
Hello,
I have a strange problem. I want to check the privilege of the login user
on each page and allow to display if has suff. priv. I am storing the
privilege is session variable.
I am checking on the page_load event like
if session("uid")="" then
response.redirect("loginverify.aspx?er=nlog")
elseif session("priv")<>0 then
response.redirect("loginverify.aspx?er=nsad")
|
by: Mark |
last post by:
I am setting up an asp.net site using the Ektron CMS. Every page in the
site uses the same basic template, with the look of the page changing
via CSS and an id on the body. The id is shared by all pages in a
subsection, e.g. everything in /about/ needs to have <body id="about">.
In the past what I've done is set a global variable in index.asp, then
include the template to render the page:
<%
pageid = "about"
| |
by: Alan Silver |
last post by:
Hello,
In classic ASP, I used to use two include files on each page, one before
and one after the main content, to provide a consistent layout across a
web site. That way I could just change the include files to change the
layout. When I came to ASP.NET, I used user controls to do a similar
thing.
I have just been looking at master pages, and it looks like they do the
same thing. If so, is there any advantage in using them over the...
|
by: edsuslen |
last post by:
I am trying to migrate from asp to asp.net and having problem replacing
include with user control.
On every page we have include asp that have some common asp code that I
need to run before the page code kicks in, but user control code is
always running after the page code.
I am even registering and placing user control before my page
initialization, but still it's running after.
<%@Register TagPrefix="FindSessionUC"...
|
by: tshad |
last post by:
User VS 2003, I would like to use User Controls to control the page look
with 3 User Controls (...PageTop.ascx, ...NavigateTop.ascx and
PageBottom.ascx). I would put the Content User control between the
NavigateTop and PageBottom User controls.
These files be something like: sdhcPageTop.ascx, ft2PageTop.ascx,
sbPageTop.ascx, macPageTop.ascx etc. I would have the same files for the
NavigateTop.ascx and PageBottom.asc.
The ones that...
|
by: remy.bur |
last post by:
Hi,
When adding an anchor (which is runat="server") in a user control, the
link generated will be based on the user control location and not on
the page which is using the control location.
For example, if the user control is located in an include folder, here
is what I will get:
<a href="include/home.aspx">
instead of
<a href="home.aspx">
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |