Hello,
After much battling, I think I am finally seeing some progress on my
first user control (thanks to the patient souls who have answered my
many questions!!). I am left with one more problem though...
As detailed elsewhere, I have identified the need to use the ViewState
to hold a flag that indicates whether or not this is the first time the
control is loaded (ie if the flag isn't in the ViewState then it's the
first time, otherwise it's not the first time). I was going to do this
with something like ViewState["NotFirstTime"] and give it a value "y".
This led me to wonder what happens if I use two instances of the control
on a page. Presumably the first one to be loaded will set the ViewState
value, and the second will read this and think it has already been
loaded.
That led me to think of using the control's ID instead, so that it would
be uniquely identified. However, if I create a user control (which could
simply be some HTML, the ASP.NET equivalent of a server-side include
file) and that contains an instance of my control called (say) "fred",
then there is nothing to stop me adding an instance of the same control
with the same name to the main page. There wouldn't be a clash as the
fred inside the user control would not be visible directly to the main
page. Trouble is, this then causes a clash in the ViewState, as there
would be two controls looking at ViewState["fred"].
So (after all that waffle), is there a way of uniquely identifying a
control in the entire page hierarchy? I assume that there will be some
ID that the ASP.NET engine uses to identify controls. Presumably these
would be unique, and would be preserved across postbacks. Can I get at
this to make my ViewState identifier unique? Or is there a better way of
doing this?
Any advice appreciated. TIA
--
Alan Silver
(anything added below this line is nothing to do with me) 6 2237
Every Control has its own ViewState. :)
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:PQ**************@nospamthankyou.spam... Hello,
After much battling, I think I am finally seeing some progress on my first user control (thanks to the patient souls who have answered my many questions!!). I am left with one more problem though...
As detailed elsewhere, I have identified the need to use the ViewState to hold a flag that indicates whether or not this is the first time the control is loaded (ie if the flag isn't in the ViewState then it's the first time, otherwise it's not the first time). I was going to do this with something like ViewState["NotFirstTime"] and give it a value "y".
This led me to wonder what happens if I use two instances of the control on a page. Presumably the first one to be loaded will set the ViewState value, and the second will read this and think it has already been loaded.
That led me to think of using the control's ID instead, so that it would be uniquely identified. However, if I create a user control (which could simply be some HTML, the ASP.NET equivalent of a server-side include file) and that contains an instance of my control called (say) "fred", then there is nothing to stop me adding an instance of the same control with the same name to the main page. There wouldn't be a clash as the fred inside the user control would not be visible directly to the main page. Trouble is, this then causes a clash in the ViewState, as there would be two controls looking at ViewState["fred"].
So (after all that waffle), is there a way of uniquely identifying a control in the entire page hierarchy? I assume that there will be some ID that the ASP.NET engine uses to identify controls. Presumably these would be unique, and would be preserved across postbacks. Can I get at this to make my ViewState identifier unique? Or is there a better way of doing this?
Any advice appreciated. TIA
-- Alan Silver (anything added below this line is nothing to do with me)
Alan Silver wrote: So (after all that waffle), is there a way of uniquely identifying a control in the entire page hierarchy? I assume that there will be
some ID that the ASP.NET engine uses to identify controls. Presumably
these would be unique, and would be preserved across postbacks. Can I get
at this to make my ViewState identifier unique? Or is there a better way
of doing this?
Any advice appreciated. TIA
-- Alan Silver (anything added below this line is nothing to do with me)
Yes, ASP.NET generates id's to make sure they are unique in cases like
this.
Google this group on "generated id" and "ClientID" and you should get
an idea of how to use this id and when it's available.
You can also set the ID property of a control with an arbitrary value
to help manage them.
HTH,
Jim
>Every Control has its own ViewState. :)
Duh, I thought it was one big ViewState shared between all controls on
the page!!
Ho hum, I've just spent ages playing with ClientID to get this working.
Oh well, I might leave it now, if it ain't broke, don't fix it ;-)
Thanks for the elucidation
--
Alan Silver
(anything added below this line is nothing to do with me)
>Yes, ASP.NET generates id's to make sure they are unique in cases like this. Google this group on "generated id" and "ClientID" and you should get an idea of how to use this id and when it's available. You can also set the ID property of a control with an arbitrary value to help manage them.
Thanks, what I didn't realise (until after I posted) was that the
ClientID includes some hierarchy detail, so even in the case I
mentioned, the two fred controls wouldn't have the same ClientID, one
would just be called fred and one would be something like
usercontrol1_fred.
Thanks for the reply.
--
Alan Silver
(anything added below this line is nothing to do with me)
I thought that would make you feel better. :)
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:y$**************@nospamthankyou.spam... Every Control has its own ViewState. :)
Duh, I thought it was one big ViewState shared between all controls on the page!!
Ho hum, I've just spent ages playing with ClientID to get this working. Oh well, I might leave it now, if it ain't broke, don't fix it ;-)
Thanks for the elucidation
-- Alan Silver (anything added below this line is nothing to do with me)
>I thought that would make you feel better. :)
Oh it does, but it also makes me feel a bit daft for having spent so
long trying to figure out how to avoid a non-existent problem!!
Ta ra
--
Alan Silver
(anything added below this line is nothing to do with me) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ross |
last post by:
Hello everybody,
When I try to configure my data adapter for ODBC I get the error "Could
not determine which columns uniquely identify the rows for "Shipments"."
This is for my update and delete...
|
by: muser8 |
last post by:
What is the best way in which to uniquely identify anonymous visitors
to an asp.net website? I'd like to create on online poll, but I want
to guard against people hitting the refresh button,...
|
by: bazzer |
last post by:
im trying to access a microsoft access database from an asp.net
webform. but when i use the OdbcDataAdapter config wizard i get the
following errors:
*Generated UPDATE statement
-could not...
|
by: bazzer |
last post by:
i am having trouble updating a datset because i get the follwing error
in the Data Adapter configuration Wizard:
Generated UPDATE statement. could not determine which columns uniquely
identify...
|
by: Anoop Nair |
last post by:
Hi
I am developing scripts in C# which can be used to test windows based
applications. I use Win32 API's to perform click operations etc. To uniquely
identify a control in a window rather than ...
|
by: 01423481d |
last post by:
Hi all
Here is a segment of code used to find out all running processes
Imports System.Diagnostics
....
Dim myProcesses() As Process
Dim myProcess As Process
|
by: Frankie |
last post by:
It appears that System.Random would provide an acceptable means through
which to generate a unique value used to identify multiple/concurrent
asynchronous tasks.
The usage of the value under...
|
by: Ryan Liu |
last post by:
Hi,
If I want to uniquely identify a computer. I can read CPU ID or Mac Address.
I heard, but is this true: some BIOS can block CPU ID from being read? (In
this case, will I get an exception,...
|
by: raylopez99 |
last post by:
A quick sanity check, and I think I am correct, but just to make
sure: if you have a bunch of objects that are very much like one
another you can uniquely track them simply by using an ArrayList...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
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...
|
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...
| |