473,803 Members | 3,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User Control an ID

Hello, i have one problem.
I use loadcontrol in default.aspx page. On page i have placeholder and on
load i with loadcontral load dynamic some user control.
Some times i must load same user control twice, like test.ascx, ockey thats
no problem. But now in test.ascx is loaded twice so how can i now
determinete in load function in user control whic one is. I also want to
create that when i load user contol in default.aspx write some parameters in
some property maybe in session[], and than read that properties but i must
read right one, if the user control is difrent then i yust write on load
session["test"]="first" session["test2"]="second" ockej on load of user
control test.asc i youst read property from session["test"] and user control
test2.ascx read from session["test2"]. This is ok but when i have one user
control loaded twice how can now write difrent parameter for sam user
control...

thanks

Nov 18 '05 #1
3 1873
Matej,
I hope I can answer your questions or atleast help a little bit.

You didn't provide us with any code, so let's say it looks something like
this:

Dim c1 as Control = Page.LoadContro l("test.ascx" )
Page.Controls.A dd(c1)
Dim c2 as Control = Page.LoadContro l("test.ascx" )
Page.Controls.A dd(c2)

Now, the solution to your problem is understanding that c1 and c2, while
both representing the same user control, are actually two separate instance
of a class. The trick to your parameter issue is simple, in the codebehind
of test.ascx, add a propeprty:

private _parameter as string
Public Property Parameter() as string
get
return _parameter
end get
set (value as string)
_parameter = value
end set
Then, back in your page, change your code to this:
Dim c1 as Test= ctype(Page.Load Control("test.a scx"), test)
c1.Parameter = "first"
Page.Controls.A dd(c1)
Dim c2 as Test= ctype(Page.Load Control("test.a scx"), test)
c2.Parameter = "second"
Page.Controls.A dd(c2)

Hope that helps.

Karl

"Matej Kavčič" <ma**********@e mail.si> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hello, i have one problem.
I use loadcontrol in default.aspx page. On page i have placeholder and on
load i with loadcontral load dynamic some user control.
Some times i must load same user control twice, like test.ascx, ockey thats no problem. But now in test.ascx is loaded twice so how can i now
determinete in load function in user control whic one is. I also want to
create that when i load user contol in default.aspx write some parameters in some property maybe in session[], and than read that properties but i must
read right one, if the user control is difrent then i yust write on load
session["test"]="first" session["test2"]="second" ockej on load of user
control test.asc i youst read property from session["test"] and user control test2.ascx read from session["test2"]. This is ok but when i have one user
control loaded twice how can now write difrent parameter for sam user
control...

thanks

Nov 18 '05 #2
Hi Matej:

A clean approach would be to add some public properties to the user
control. When the control is dynamically created you could set these
properties on the control. This approach means you dont have to put
data in the Session for later, and the control's do not need to figure
out in what order they were created.

Does this make sense?
Does this work for your requirements?

--
Scott
http://www.OdeToCode.com

On Thu, 19 Aug 2004 14:10:22 +0200, "Matej Kavčič"
<ma**********@e mail.si> wrote:
Hello, i have one problem.
I use loadcontrol in default.aspx page. On page i have placeholder and on
load i with loadcontral load dynamic some user control.
Some times i must load same user control twice, like test.ascx, ockey thats
no problem. But now in test.ascx is loaded twice so how can i now
determinete in load function in user control whic one is. I also want to
create that when i load user contol in default.aspx write some parameters in
some property maybe in session[], and than read that properties but i must
read right one, if the user control is difrent then i yust write on load
session["test"]="first" session["test2"]="second" ockej on load of user
control test.asc i youst read property from session["test"] and user control
test2.ascx read from session["test2"]. This is ok but when i have one user
control loaded twice how can now write difrent parameter for sam user
control...

thanks


Nov 18 '05 #3
Thanks i do with public property in user control i create my own derived
user control, thanks for advice
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:p6******** *************** *********@4ax.c om...
Hi Matej:

A clean approach would be to add some public properties to the user
control. When the control is dynamically created you could set these
properties on the control. This approach means you dont have to put
data in the Session for later, and the control's do not need to figure
out in what order they were created.

Does this make sense?
Does this work for your requirements?

--
Scott
http://www.OdeToCode.com

On Thu, 19 Aug 2004 14:10:22 +0200, "Matej Kavčič"
<ma**********@e mail.si> wrote:
Hello, i have one problem.
I use loadcontrol in default.aspx page. On page i have placeholder and on
load i with loadcontral load dynamic some user control.
Some times i must load same user control twice, like test.ascx, ockey
thats
no problem. But now in test.ascx is loaded twice so how can i now
determinete in load function in user control whic one is. I also want to
create that when i load user contol in default.aspx write some parameters
in
some property maybe in session[], and than read that properties but i must
read right one, if the user control is difrent then i yust write on load
session["test"]="first" session["test2"]="second" ockej on load of user
control test.asc i youst read property from session["test"] and user
control
test2.ascx read from session["test2"]. This is ok but when i have one user
control loaded twice how can now write difrent parameter for sam user
control...

thanks

Nov 18 '05 #4

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

Similar topics

6
11305
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header" Src="WebControls/Header.ascx" %> The web user control contains the following server controls
1
7591
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
6
3383
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all the usual stuff of recreating the usercontrol in the Page Init event. The 'failure' sequence is as follows: - select web form button to display the user control - select user control button, event fires - select web form button to display...
4
2518
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once I have exposed a public property containing the value of a textbox in a user control..how do I grab this from the calling page? I cant think of the syntax, since my page doesnt know the contents of the class (and therefore, the public...
0
3939
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something like this is a bug or that .NET doesn't support what I trying to do. I hope that one that is is microsoft certified read this because this must be a bug.
8
3029
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the way I'm going about doing this might be a little off. I'd appreciate some help. Below is the code I have thus far but I'm not sure how to reference the user control within the foreach loop. <asp:Panel ID="pnlRosterProfile" runat="Server" />
0
3443
by: davidr | last post by:
Hi, I have a panel that I load user Control in no problem. The problem arrises when I do a post back on one of these user controls. I have button it does a click event. In this click event I will do some database updates, then I will use reflection to call a method in the parent (this.page) to load the new user control. Its at this point after it loads the new user control that it throws the error "The control must be placed inside...
2
4828
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be required: <%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %> Assuming that the ASPX page doesn't use a code-behind, I can access the properties, events etc. of the user control in the ASPX page in this way (assume that the ASPX page...
2
15076
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
3
1927
by: Fred Chateau | last post by:
I am trying to access a user control class, for a user control that is loaded dynamically, from the containing page. I have been able to access Web controls in the user control, but so far I have been unable to expose the user control class itself. I'm guessing that I need to set up an interface, but I am not sure how to accomplish this. Here is the code that loads the user control: protected void Page_Init(object sender, EventArgs e)...
0
9699
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
9562
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
10309
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
10289
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
9119
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, 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...
1
7600
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
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4274
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
2
3795
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.