Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2005, 10:10 AM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default setting a web control's ID programatically

is it possible to set a web control's "ID" property programatically?
for instance?

Code:
Dim myControlId As String

myControlId = "idWhatever"
.
.
.
.
<asp:button id='<%# myControlId%>' ....

 
Old January 24th, 2005, 11:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I don't think like that, you can set it in code-behind as such:

myControlId.ID = "idWhatever"

Brian
 
Old January 24th, 2005, 12:12 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by bmains
 I don't think like that, you can set it in code-behind as such:

myControlId.ID = "idWhatever"

Brian
thanks for the reply Brian but you have really confused me. in your snippet myConrtrolId, i think, references a control by its id value. therin lies my problem, the id is what i'm trying to set. according to my understanding one can set all properties per your example except for the id.

 
Old January 24th, 2005, 02:50 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

AFAIK, you cannot set the ID of a control in the ASPX portion of the code dynamically.

However, you can do something like this:

Dim myTextBox As TextBox = New TextBox()
myTextBox.ID = "WhatEverYouWantItToBe"
MyPlaceHolder.Controls.Add(myTextBox)

Then in your ASPX add a placeholder like this:

<asp:PlaceHolder id="MyPlaceHolder" runat="server" />

This allows you to create a textbox on the fly, set its ID and add it to the page dynamically.

Be aware of the ID: If you're adding the control to another repeating control (like a DataGrid or the Repeater) you'll need to make sure the ID is unique in the scope. I think you can use INamingContainer for that, but I can't remember how to use that exactly. I am also not sure if the container control handles this automatically for you, so you'll need to do a bit of testing to make sure this works.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Die Interimsliebenden by Einstürzende Neubauten (Track 1 from the album: Tabula Rasa) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting of web config file epkgupta General .NET 0 July 9th, 2008 09:32 AM
Setting logged in UserName to Session ID Admiral1701 ASP.NET 2.0 Professional 10 December 1st, 2006 10:35 AM
Setting the Locale within Web.Config rit01 ASP.NET 2.0 Basics 1 March 2nd, 2006 11:06 AM
Can I get a Web Control's Variable Name? MAtkins ASP.NET 1.0 and 1.1 Professional 6 October 2nd, 2005 01:01 PM
setting connection string in the web.config ACE2084 ADO.NET 2 January 6th, 2005 04:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.