Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Naming Container difference between VS2003 and VS2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Monty - 04 Dec 2007 21:39 GMT
I have an ASP.Net project I developed in VS2003 (ASP.Net 1.1) that works
fine, but when I convert it to VS2005 (ASP.Net 2.0) it's behavior seems to
change. I have the following datagrid in my project:

<asp:datagrid id="grid" runat="server" AutoGenerateColumns="False"
AllowSorting="False" DataKeyField="myID">
   <Columns>
       <asp:TemplateColumn HeaderText="Action">
           <ItemTemplate>
               '''''''NOTE FOLLOWING LINE:
               <input Runat="server" ID="SelectedRequest" type="hidden"
                           NAME="SelectedRequest" />
               '''''''NOTE PREVIOUS LINE ^
               <asp:Literal Runat="server" ID="litRadioButtons" />
           </ItemTemplate>
       </asp:TemplateColumn>
       <asp:TemplateColumn HeaderText="Action Message">
           <ItemTemplate>
               Message:<br>
               <asp:TextBox ID="txtMessage" Runat="server" />
           </ItemTemplate>
       </asp:TemplateColumn>
   </Columns>
</asp:datagrid>

When I run this page in VS2003, the line noted above is rendered as:

<input name="grid:_ctl2:SelectedRequest" id="grid__ctl2_SelectedRequest"
type="hidden" />

But when I run my converted project in VS2005, it is rendered as:

<input name="SelectedRequest" type="hidden" id="SelectedRequest" />

What am I missing here? Why isn't the ID of my input control being modified
by it's naming container?

TIA.
Walter Wang [MSFT] - 05 Dec 2007 11:05 GMT
Hi Monty,

I've tested it on my side and wasn't able to reproduce the issue you
described:

Output from ASP.NET 1.1

               <input name="grid:_ctl2:SelectedRequest"
id="grid__ctl2_SelectedRequest" type="hidden" />

Output from ASP.NET 2.0:

               <input name="grid$ctl02$SelectedRequest" type="hidden"
id="grid_ctl02_SelectedRequest" />

As you can see, only the name is changed using a different separator (which
is expected behavior -- MSDN document already stated that developers should
not use hardcoded id separator).

Would you please tell me more about your configuration? Thanks.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Monty - 06 Dec 2007 17:09 GMT
I've created a simple demo page which should clearly demonstrate the issue
I'm having. Using the demo page (below) as is, my hidden input controls are
rendered as:
<input name="SelectedRequest" type="hidden" id="SelectedRequest" />
However, if I comment out the four lines in the ItemCreated event, my hidden
input controls are now rendered as:
<input name="grid:_ctl2:SelectedRequest" type="hidden"
id="grid__ctl2_SelectedRequest" />

The results are all from within VS2008 targeting the 2.0 Framework. Can you
tell me what is causing the change in the client IDs? Thanks.

Here is my demo page:

<%@ Page Language="vb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script runat="server">
   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
       grid.DataSource = New Integer(5) {}
       grid.DataBind()
   End Sub

   Private Sub grid_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles grid.ItemCreated
       Dim oLit As System.Web.UI.WebControls.Literal =
e.Item.FindControl("litRadioButtons")
       If Not oLit Is Nothing Then
           System.Diagnostics.Debug.Print(CType(e.Item.FindControl("SelectedRequest"),
System.Web.UI.Control).ClientID)
       End If
   End Sub
</script>
<html>
<head>
   <title>Test Client IDs</title>
</head>
<body>
   <form id="Form1" method="post" runat="server">
   <asp:DataGrid ID="grid" runat="server" AutoGenerateColumns="False"
AllowSorting="False" >
       <Columns>
           <asp:TemplateColumn HeaderText="Action">
               <ItemTemplate>
                   <input runat="server" id="SelectedRequest" type="hidden"
name="SelectedRequest" />
                   <asp:Literal runat="server"
ID="litRadioButtons"></asp:Literal>
               </ItemTemplate>
           </asp:TemplateColumn>
       </Columns>
   </asp:DataGrid>
   </form>
</body>
</html>
Walter Wang [MSFT] - 07 Dec 2007 02:48 GMT
Hi Monty,

Is this the same code logic as you were using in VS2003 and it worked
correctly?

I have reproduced the issue you mentioned in VS2008. The issue seems
related to accessing the control's ClientID property in the ItemCreated
event. I will do some more research and get back to you later.

Thanks for your feedback.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 07 Dec 2007 02:58 GMT
Hi Monty,

Well, I have just found out it's a known issue of ASP.NET 2.0, we have an
open bug record for it.

Some explanation of this issue:

When ClientID is called, part of the operation is to retrieve the naming
container prefix to return the full client ID (with naming container
prefix), through the calling of UniqueID property. At the time ItemCreated
event is called, the control created in the event has not been added to the
control tree. It is added to the control tree after the event is done in
DataGrid's code. So you observed that ClientID returns only the ID in
ItemCreated event.

In v1.x, the UniqueID is computed everytime the property is called, meaning
that the control would walk up the tree to gather the necessary id prefix
for the naming containers. In v2.0, for better performance, we introduced
some caching code so the control tree walk up would only be done once for
the first time it is being accessed.

As a workaround, we should avoid calling ClientID in ItemCreated event.

If this workaround doesn't work for you, please contact our Customer
Support and Service to see if there will be hotfix available before it's
fully fixed in future versions. We're sorry for the inconvenience caused.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Monty - 07 Dec 2007 03:44 GMT
Hi Walter,

Thanks for the research. Do you have KB number for this? Do you know if this
issue is resolved with v3.5?

Thanks again...
Monty - 09 Dec 2007 15:20 GMT
For anyone following along, no this issue has not changed in the 3.5
Framework, but I was able to work around this issue by moving my code from
the ItemCreated event to the ItemDataBound event. Good luck!
Walter Wang [MSFT] - 10 Dec 2007 05:10 GMT
Hi Monty,

The public KB is under development.

Thanks for your feedback, this will certainly benefit others if they also
encouter this issue.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.