Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 April 27th, 2012, 11:35 AM
Friend of Wrox
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default Chapter 11 - Excercise 1 (ClientIDMode)

Hi Imar,

I had another question about Exercise 1...

In this exercise the ClientIDMode of VerticalPanel is set to static. I'm confused since on page 314, it recommends to use the ClientID to get the controls's client ID at runtime?

I'm assuming that ClientIDMode of VerticalPanel is set to static because it makes the problem a bit easier, but in a real project you would use the ClientID to get the control's client Id at runtime?

I'm confused as to which is the correct way?

Thank you for all your help.

Tulsi
 
Old April 29th, 2012, 06:09 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
but in a real project you would use the ClientID to get the control's client Id at runtime?

I'm confused as to which is the correct way?
You probably would use both, depending on the scenario. ClientID is useful inside a page as you can directly access the control and this property. However, when you're writing code in a separate JavaScript file you don't have access to the control, and thus you may have the need to hardcode the ID there (although in those cases it's often better to not hard code the ID, but to use a CSS class instead and query elements by the class name).

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 30th, 2012, 01:26 PM
Friend of Wrox
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Thank you...This makes sense.

Just wondering if you could do the following:

var PanelName = document.getElementById('<%= VerticalPanel.ClientID %>' );
and then using the PanelName in Jquery selector? Can this be done?

Thanks,
Tulsi
 
Old April 30th, 2012, 02:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Tulsi,

The best answer is: why don't you try it out. This way, you get hands-on experience while trying to make it work ;-)

The second best answer is: absolutely. Don't forget to include the # symbol as that's not part of the client ID. E.g.:

$('#' + PanelName).WhatEverjQueryCodeHere();

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 30th, 2012, 02:34 PM
Friend of Wrox
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Good suggestion :). I tried it out and modified the jquery code as follows:

<script type="text/javascript">
$(function () {

var PanelName = document.getElementById('<%= VerticalPanel.ClientID %>');

$('#HideBanner').bind('click', function ()
{
$('#' + PanelName).slideToggle('fast', function ()
{
if ($(this).css('display')=='block')
{
$('#HideBanner')[0].innerText = "Hide Banner";
}
else
{
$('#HideBanner')[0].innerText = "Show Banner";
}
});
});
});
</script>

I tried different variations. For ex., I changed the declaration to var PanelName = document.getElementById('VerticalPanel'); But I still get an error.

Thank you.

Tulsi
 
Old April 30th, 2012, 03:21 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Oooops, looks like I made a mistake....

This:

Code:
 
var PanelName = document.getElementById('<%= VerticalPanel.ClientID %>');
gives you a reference to a DOM element, not just its ID. So, # + PanelName won't work.

You could wrap the element in a jQuery set.E.g.:

Code:
 
$(PanelName).slideToggle('fast', function ()
should work. If it does, you could rename PanelName to something like panel, as it represents the entire panel element, not just its name / ID.

When you post code, can you wrap them in code (#) tags using the toolbar? Makes it easier to read.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 1st, 2012, 12:58 PM
Friend of Wrox
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

This worked....Thank you for the help.

Tulsi





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 11 - Excercise 1 Tulsi BOOK: Beginning ASP.NET 4 : in C# and VB 3 April 29th, 2012 06:32 AM
Chapter 4 Excercise 2 [email protected] BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 8 August 19th, 2010 11:24 PM
chapter 11 figure 11-7 relative positioning pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 November 29th, 2007 06:11 AM
Excercise answers for book GrantWillie C# 0 October 22nd, 2003 05:07 AM
C#,chapter 8 excercise akbard BOOK: Beginning ASP.NET 1.0 2 October 7th, 2003 03:25 AM





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