473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 1831
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.LoadControl("test.ascx")
Page.Controls.Add(c1)
Dim c2 as Control = Page.LoadControl("test.ascx")
Page.Controls.Add(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.LoadControl("test.ascx"), test)
c1.Parameter = "first"
Page.Controls.Add(c1)
Dim c2 as Test= ctype(Page.LoadControl("test.ascx"), test)
c2.Parameter = "second"
Page.Controls.Add(c2)

Hope that helps.

Karl

"Matej Kavčič" <ma**********@email.si> wrote in message
news:%2****************@tk2msftngp13.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**********@email.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.com...
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**********@email.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
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"...
1
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...
6
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...
4
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...
0
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...
8
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...
0
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...
2
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...
2
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...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.