Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion 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 September 10th, 2010, 10:13 AM
Friend of Wrox
 
Join Date: Mar 2010
Posts: 99
Thanks: 21
Thanked 6 Times in 4 Posts
Default FindControl question and a MasterPage question about controls

Hello,

Ive got two questions i am trying to figure out the real answer.

1- This one is related to the FindControl fonction. In one of my project i use a masterpage with a page.. the container id name is "content".

It is okay to reach the control directly this way : this.FindControl("ctl00$contenue$txtMotif") ? because it seem to work rather well (i don't need to pass through containers..) if you are able to predict the resulting ID.. i guess we could also use Control.ClientID ?

2- My second question is regarding the masterpage and controls events.. i was wondering why is the page controls events are handled before the masterpage control events ? Should it be more normal to handle controls in masterpage first since its the first generated part of the page ? or i am all wrong ?

Thanks.
 
Old September 11th, 2010, 02:47 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 Rushino,

1) If it works, it works. But with string literals you do indeed run the risk of naming problems. If the ClientID works, you should use that instead. The only problem is: how do you get the ClientID? If you have it, you already have a reference to the control so there's no need for FindControl.... ;-)

2) A master page is not created first. Confusing as it may sound, a Master Page actually turns up as a child control of the page. More details can be found here, in particular Figure 7: http://msdn.microsoft.com/en-us/magazine/cc163967.aspx

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 September 11th, 2010, 11:35 AM
Friend of Wrox
 
Join Date: Mar 2010
Posts: 99
Thanks: 21
Thanked 6 Times in 4 Posts
Default

Hi Imar,

Thanks for your answer. I will try to elaborate a little more about what i am doing.

I am making a system that actually save every controls which has ID with "txt" in it.. (mean be to textbox) it save the infos in a BD.. so whatever someone add a new control to the page.. it should save the new controls auto to the DB.

What i am saving also.. are the control ID.. to do so.. i go through the POST request and find every control that contains a "txt" word in the ID then im saving the whole control id which is ctl00$contenue$txtMotif as an example for a control. Then when i load back the info.. i use this id with the find control.. every control will get a different name anyway cause most of the control have question number in the ID.

You said "how do you get the ClientID? If you have it, you already have a reference to the control so there's no need for FindControl.... " what did you mean ? in order to get that control i need to pass that reference to the findcontrol.. and cast it to an actual control type.. otherwise i cant access his properties.
 
Old September 11th, 2010, 03:17 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
in order to get that control i need to pass that reference to the findcontrol.. and cast it to an actual control type.. otherwise i cant access his properties.
Exactly. And thus you can't access its ClientID property. You can use the value that is eventualy exposed by the ClientID property of the control if you know it upfront (that's how you use FindControl) but you can't access the Control's ClientID property until you have a reference to that control.

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Masterpage Update Panel Question jazzcatone ASP.NET 2.0 Basics 1 June 14th, 2007 09:20 AM
Masterpage Question and Misprint on page 269 stanguss BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 February 24th, 2006 11:31 AM
Events in User Controls question Aaron Edwards ASP.NET 1.0 and 1.1 Basics 1 December 6th, 2005 02:59 PM
Extending Controls Question eberly General .NET 0 June 21st, 2005 12:32 PM
Controls question Warbird General .NET 0 January 25th, 2005 11:56 AM





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