Wrox Programmer Forums
|
BOOK: Professional ASP.NET 1.0, Special Edition/1.1
This is the forum to discuss the Wrox book Professional ASP.NET 1.1 by Alex Homer, Dave Sussman, Rob Howard, Brian Francis, Karli Watson, Richard Anderson; ISBN: 9780764558900
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 1.0, Special Edition/1.1 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 October 20th, 2003, 03:08 PM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to lmxu
Default Server Control ID

Hello,

I'm looking for a way to assign dynamic ID to server controls without using the <asp:placeholder> and then add the server control to the placeholder in my code-behind.

For example,

I want something like <asp:panel ID="<%=i%>" runat="server" /> ...
but I'm getting an error <%=i%> is not a valid identifier.. I also tried with single quote '<%=i%>'

any help will be helpful. thanks.

--------------------
Edit post


BTW... I also noticed that a variable value is losted with in <asp:panel>

for example

<% for (int i=0; i<3; i++){%>

   <asp:panel ID="test">
         <%=i%>
   </asp:panel>

<% } %>

I would get an error "The name 'i' does not exist in the class or namespace 'ASP.test_page.aspx'

The reason I don't use a DataList/Repeat/etc in this situation is purely for testing purpose. Thanks again

Any Clues?
 
Old November 19th, 2003, 07:40 AM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello..
i am new to asp.net and xml...i have got a page with links ..what i want is...when i click on a link it will call and aspx page and depending on which link is clicked the perticular xml file will be loaded...please help...
Thanks

 
Old November 20th, 2003, 06:41 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

What you're trying to do is not possible. You can't create dynamic IDs when creating controls with declarative syntax.

What you could do is create the controls in code (in your Code Behind page, or in a method in code in your ASPX page). You can assign IDs to the controls and then add them to the page, like this:
Code:
Label myLabel = null;
for (int i = 0; i < 10; i++)
{
    myLabel = new Label();
    myLabel.ID = "lbl" + i.ToString();
    myLabel.Text = "Label " + i.ToString();
    this.Controls.Add(myLabel);
}
This will add a bunch of Labels to the page, each with a different, dynamically generated ID.

What exactly are you trying to accomplish? The code I posted here will get you into troubles when you try to access these controls and their values again because they no longer exist.

If you need repeating controls, take a look at the the asp:Repeater control. It's designed to repeat data and allows for nested controls.

HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting id of a control in javascript sudhir164 Javascript How-To 2 February 23rd, 2008 05:35 AM
How to get the id of an image control jasdeephere ASP.NET 1.0 and 1.1 Professional 3 January 30th, 2007 09:06 AM
Master pages &server control ID - asp.net 2.0 tech user C# 2005 1 August 3rd, 2006 04:31 AM
how to get ID of server-control in Javascript? hertendreef ASP.NET 2.0 Basics 0 June 15th, 2006 12:05 PM
Get the Id of Control in ASP rekha_jsr Classic ASP Professional 2 June 14th, 2006 07:37 AM





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