472,954 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Getting the server-adjusted ID of a repeated user control

Hi,

Outline of problem:

I've built a set of user controls that are used to output questions for a
survey and gather the responses using simple radio buttons.

I'm adding an optional textbox to the question control to allow individual
typed responses per question. I've got a maximum length to enforce which
matches the underlying data table design.

When asp.Net outputs a textbox set to multiline mode, the server actually
outputs a textarea tag. Fine, but I've found that the MaxLength property
seems to get ignored. I have previously got around this by providing a
javascript function to update a display of the characters remaining and
adding an Attribute to the specific textbox when the page loads that fires
the javascript function on the "onkeyup" event.

The javascript is straight-forward enough and the function allows a pair of
object names to be passed in, which correspond to the text entry textbox and
the chars remaining display textbox.

The issue I am having a problem with is that due to the question control
being repeated multiple times down the page, the server also adds a custom
prefix to each element ID that extends the original ID, so when I need to
add the attribute, I also need to know the adjusted ID of the specific
instance of the textbox.

Example output steps:

1. Out put header label values
2. Start outer loop to output question block header
3. Step 2 makes call to a second loop that outputs questions for the block

For example, the original ID of "txtResText" might become
"ctl109_txtResText", with the "ctl109_" bit varying according to how many
instances of the textbox there are. This is complicated a little as the
question control is not the only control being added to the page. There are
a set number of "static" controls that are output from the database. This
is important as it makes the starting number of the prefix higher than a
simple zero-indexed count of the question control on its own.

Say I have three "normal" labels populated before the repeated controls are
reached. These controls ID's remain unaffected, but they make the prefix of
the repeated control ID's start at "ctl104_".
My proposed solution:

I could use this knowledge to create a counter (with an offset to accomodate
the non-looped controls) that increments along with the output loops of the
various user controls, but this seems like a "hammer to crack a nut"
approach. Also, If I ever wanted to add further output prior to the loops
starting, I would have to remember to adjust the offset of the counter.
The real question:

Is there a more elegant way of achieving this? For example, is there a way
of getting the VS2005 IDE to tell me what the ID prefix would be?
Thanks for any help.

Al
Nov 13 '06 #1
1 1831
skip the id altogether.

ctl.AddAttribute('onkeyup',string.Format('textarea max(this,{0});',maxlength));

in client

function textareamax(e,m) {
if (e.value.length m) e.value = e.value.substr(0,m);
}

-- bruce (sqlwork.com)
"Alec MacLean" <al**********@NO-SPAM-copeohs.comwrote in message
news:u6*************@TK2MSFTNGP03.phx.gbl...
Hi,

Outline of problem:

I've built a set of user controls that are used to output questions for a
survey and gather the responses using simple radio buttons.

I'm adding an optional textbox to the question control to allow individual
typed responses per question. I've got a maximum length to enforce which
matches the underlying data table design.

When asp.Net outputs a textbox set to multiline mode, the server actually
outputs a textarea tag. Fine, but I've found that the MaxLength property
seems to get ignored. I have previously got around this by providing a
javascript function to update a display of the characters remaining and
adding an Attribute to the specific textbox when the page loads that fires
the javascript function on the "onkeyup" event.

The javascript is straight-forward enough and the function allows a pair
of object names to be passed in, which correspond to the text entry
textbox and the chars remaining display textbox.

The issue I am having a problem with is that due to the question control
being repeated multiple times down the page, the server also adds a custom
prefix to each element ID that extends the original ID, so when I need to
add the attribute, I also need to know the adjusted ID of the specific
instance of the textbox.

Example output steps:

1. Out put header label values
2. Start outer loop to output question block header
3. Step 2 makes call to a second loop that outputs questions for the block

For example, the original ID of "txtResText" might become
"ctl109_txtResText", with the "ctl109_" bit varying according to how many
instances of the textbox there are. This is complicated a little as the
question control is not the only control being added to the page. There
are a set number of "static" controls that are output from the database.
This is important as it makes the starting number of the prefix higher
than a simple zero-indexed count of the question control on its own.

Say I have three "normal" labels populated before the repeated controls
are reached. These controls ID's remain unaffected, but they make the
prefix of the repeated control ID's start at "ctl104_".
My proposed solution:

I could use this knowledge to create a counter (with an offset to
accomodate the non-looped controls) that increments along with the output
loops of the various user controls, but this seems like a "hammer to crack
a nut" approach. Also, If I ever wanted to add further output prior to
the loops starting, I would have to remember to adjust the offset of the
counter.
The real question:

Is there a more elegant way of achieving this? For example, is there a
way of getting the VS2005 IDE to tell me what the ID prefix would be?
Thanks for any help.

Al

Nov 13 '06 #2

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

Similar topics

8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
2
by: Praveen | last post by:
Hi All, I have made a webservice in C# and it works fine in my machine. I ran into a crazy problem when I wanted to deploy it in windows 2003 server. I have run "aspnet_regiis.exe -i" to make...
14
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
3
by: Rahul Anand | last post by:
As per our requirements we have a web service which internally connects (Simple HTTP Post Request) to a remote server to initiate some work. We are calling the web service method asynchronously...
1
by: Nurm | last post by:
We have a live webserver that is running .net 1.1 and 2.0 (mainly 1.1 websites). This morning we put a .net 2.0 test website onto the server and are getting http 404 errors. The 2 different...
41
by: LayneMitch via WebmasterKB.com | last post by:
I was just chating with a few webdevelopers and it was brought to my attention that I need some type of server technology installed on my computer so I could get a visual of how my sites would look...
1
by: =?Utf-8?B?Q29kZVNsaW5nZXI=?= | last post by:
I plan to build my own 2008 Server/Hyper-V system and will not be using one of the tested Dell or HP systems from the release notes and could use some pointers as to my assumnptions and answers to...
1
by: Rahul | last post by:
I am getting following error: 1) For a xml file "Request.xml" we created a schema "Request.xsd". 2) With the help of xsd.exe we got the C# file Request.cs. 3) We tried to send the object of...
2
by: Scott | last post by:
I'm debugging an xmlrpc client/server application. Often when an exception occurs in the server, I receive only a very short error message on the client. For example: xmlrpclib.Fault: <Fault 1:...
1
by: Ramchandar | last post by:
Hi, I have an ASP.Net web application hosted in my local server with IIS 5.0 as web server. This worked fine with no issues. So I tried hosting the same into the server machine where I have IIS...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.