HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
Go Back  Xtreme Visual Basic Talk > > > HELP with accessing controls within 3rd party Tab Control tags


Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2008, 09:50 AM
Rikki Rikki is offline
Freshman
 
Join Date: Jan 2008
Location: Waterloo, ON
Posts: 47
Unhappy HELP with accessing controls within 3rd party Tab Control tags


I am using Visual Web Developer 2005 EE, and just a warning I am new to VB and asp.net.

I am using a free Tab Control from asplib.net and have the tabs within <ConentTemplate> tags, part of the control. I also have the option to insert them as separate pages which I have done for a different tabbed page and it works fine. I don't want to do it for this page though because it would involve creating a seperate page for each tab, and I have a save button outside of the tabs that works for all tabs regardless of whether the page being saved is new or is being updated. Having it on the page and having the contents it's saving on separate pages would involve making a new method on each tabs page and calling them, but any time I have tried calling methods on different pages I have ended up having to give up and find another way. Also it would be quite time consuming to separate the back end code for each tab.

The problem is that the back end code does not recognize any controls referenced that are within the tab tags. I believe there is a way to to have them recognized by adding a line at the top of the class (an inherits statement perhaps?) but I am not sure. Does anyone have any suggestions/ideas?

I tried using findcontrol but It only works if I have e.item.FindControl and there is nowhere that i can use 'item'. Also, I have quite a few controls so it would be quite a nuisance to do that for every single one. I also looked into setting focus to within a tab but i can't figure out how, I couldn't even get it to work for one field. I am completely stumped. I have attached the .aspx file so everyone can see how the control is set up. Any help is greatly appreciated!!

--Rikki
Attached Files
File Type: zip Employees.zip (2.4 KB, 1 views)
Reply With Quote
  #2  
Old 03-27-2008, 10:39 AM
shaul_ahuvaHELP with accessing controls within 3rd party Tab Control tags shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

You should be able to use "FindControl" - it's just a matter of finding out what the naming container is for the contained controls in a tab.

Here are my suggestions: First, see if the tab control supports either a property like "SelectedTab" or something like a "Tabs" property with a "SelectedIndex" property. Hopefully, either one would give you access to the tab item (which is probably the naming container for the controls).

If the tab control doesn't support these properties, then I would handle an event that gives you a reference to the tab item (such as a selected index changed event). Set a breakpoint in the handler, run the application in the debugger and cause the event to fire.

Once you have access to the tab item (e.g. e.Item), check to see what the type of it's naming container is (i.e. e.Item.NamingContainer). If the tab item doesn't support the NamingContainer property, then it's not a control and it can (hopefully) be assumed that the sender of the event is the naming container.

Once you have a reference to the naming container, you can follow the chain of logical parents up the hierarchy until you get to either the tab control or the containing page.

The point of all of this is that once you have the naming container, you can use FindControl on the naming container to get references to the controls in the tab page.

Another possibility is that the tab control created member variables for each tab page, and the child controls would be accessible through the member variables.

Unfortunately, I've seen all three implementations out there in the wild. Discovering how to reference your template-based controls is generally one part knowing the ASP.NET framework (e.g. knowing how the Parent, ID and NamingContainer properties are used) and nine parts playing around until you discover the magic combination of properties and objects necessary to do what you want.

If you are unaware of it, I would highly suggest Lutz Roeder's Reflector - it really helps see what is going on behind the scenes.
Reply With Quote
  #3  
Old 03-27-2008, 10:51 AM
Rikki Rikki is offline
Freshman
 
Join Date: Jan 2008
Location: Waterloo, ON
Posts: 47
Default

There is a SelectedTab property. Are you saying I should be able to do something along the lines of Me.tabcontrolID.SelectedTab.item.FindControl? There is no Item option under SelectedTab.

Also, not to be whiney, but is there not an easier way to do it? The second page I will be putting tabs on has 60+ controls I would need to find.
Reply With Quote
  #4  
Old 03-27-2008, 11:23 AM
shaul_ahuvaHELP with accessing controls within 3rd party Tab Control tags shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Well, I downloaded their library to check it out. The SelectedTab property is an integer, so it must be the index into the TabPages property. Each TabPanel is in the TabPages collection, so Me.Tabs.TabPages(Me.Tabs.SelectedTab) gets you the selected tab.

Is there any easier way? How you access the generated content is up to the developers. In my experience, there are many developers and companies out there that are good at making things look good but aren't so great at designing a clean, self-documenting API to use said flashy widgets.

At any rate, they recommend putting all of your controls for a tab page in a UserControl and putting the UserControl in the tab page. I assume they suggest this so you can do the following:

(Assume a UserControl of "TabGeneral" contains the controls in your current "General" tab, and the "General" tab contains a single "TabGeneral" control named "generalContent".)
Code:
Dim tab As TabGeneral = DirectCast(Me.Tabs.TabPages(Me.Tabs.SelectedTab).FindControl("generalContent"), TabGeneral)

Dim id As Label = tab.lblID
.
.
.
You could also keep your current layout and do something like the following to save on typing:
Code:
Dim tab As TabPanel = Me.Tabs.TabPages(Me.Tabs.SelectedTab)

Dim id As Label = DirectCast(tab.FindControl("lblID"), Label)
.
.
.
However, since TabPanel doesn't implement INamingContainer (I have NO idea why not) you'll probably experience problems if you have child controls with the same ID on different tabs. This is probably another reason why they suggest using a user control.
Reply With Quote
  #5  
Old 03-27-2008, 01:15 PM
Rikki Rikki is offline
Freshman
 
Join Date: Jan 2008
Location: Waterloo, ON
Posts: 47
Default

Alright I think I got ya. If I separate each tab into separate UserControls and put
Code:
Dim tab As TabGeneral = DirectCast(Me.Tabs.TabPages(Me.Tabs.SelectedTab).FindControl("generalContent"), TabGeneral)
in page load along with "Dim id as label = tab.lblID" for each control, I should be able to keep the code in the main page's behind code. Have I got that right?

But, as opposed to putting the "Dim id as label = tab.lblID" line for each code, would it work if I just change current Me.lblID references to tab.lblID? If it knows lblID exists then it should know it is a label shouldn't it?

One thing to complicate things though. You're right, their (useless) support said to use usercontrols. On another tabbed page the pages were already separated so I just put them in, not changing them to usercontrols. It looks like this:
Code:
<form id="form1" runat="server">
        <al:TabControl ID="Tabs" runat="server" HoverFont-Underline="True" SeparatorImage-Border=""
            BorderColor="#065AC7" BackColor="WhiteSmoke" Font-Strikeout="False" ForeColor="White"
            Height="500px" SelectedFont-Strikeout="False" TabBackColor="6, 90, 199" Width="993px">
            <al:Tabframe Url="c3.aspx" text="C3 Group Company Names" runat="server" />
            <al:Tabframe Url="Maintain.aspx" text="Maintain Employees" runat="server" />
            <al:Tabframe Url="trades.aspx" text="Trades, Training &amp; Skills" runat="server" />
            <al:Tabframe Url="location.aspx" text="Locations" runat="server" />
            <al:Tabframe Url="sizes.aspx" text="Sizes" runat="server" />
            <al:TabFrame Url="Unions.aspx" Text=Unions runat="server" />
        </al:TabControl>
    </form>
Should I keep them as TabPanels with <ContentTemplate> then put in a usercontrol, or should I use TabFrames instead?

Last edited by Rikki; 03-27-2008 at 01:34 PM.
Reply With Quote
  #6  
Old 03-27-2008, 03:57 PM
shaul_ahuvaHELP with accessing controls within 3rd party Tab Control tags shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Yes, you would change the control references to go through the reference to the tab's content control.

Would I change existing controls? There's something to be said for consistency, but unless there's some compelling need to go back and convert the other controls I probably wouldn't do so at this point. One thing you can do is just put a "TODO: Change to user controls" comment in, and if you ever need to go back and fix/change the code you could possibly do so at that time.

All of that being said, I would actually recommend a different approach (now that my brain is functioning a little better - migraines, gotta love 'em):

Create an interface as follows:
Code:
Public Interface ITab
    Sub Save(dr As DataRow)
End Interface
Implement the above interface on each user control that requires save functionality:
Code:
Partial Class TabGeneral
    Implements ITab

    Public Sub Save(dr As DataRow) Implements ITab.Save
        dr("ID") = lblID.Text
        dr("Name") = Name.Text
        ...
    End Sub
End Class
Then, all you really need to do is call the Save method from your page:
Code:
Dim tab As ITab = DirectCast(Me.Tabs.TabPages(Me.Tabs.SelectedTab).ChildControls(0), ITab)

'Let's say we're saving into a DataRow defined as "dr"...
If Not tab Is Nothing Then tab.Save(dr)
The benefits of this approach are threefold:
- The knowledge of the inner workings of each tab is known only to the tab itself and can therefore change without breaking anything else (following OOD/OOP).
- The page-level code can become even more generic (increasing maintainability)
- If necessary, you can re-use individual tabs on other pages by simply dropping them into place (increasing extensibility). Also, the "save" code won't need to be copied (increasing maintainability).
Reply With Quote
  #7  
Old 03-28-2008, 06:57 AM
Rikki Rikki is offline
Freshman
 
Join Date: Jan 2008
Location: Waterloo, ON
Posts: 47
Default

Okay, this sounds like a good approach but you've lost me. Before this project I had never even seen vb or asp.net. I'm not quite sure where this all goes, a few questions to clear things up if you don't mind:

1) Am I splitting up the current code and putting it in the behind code for the usercontrols?

2) What is a datarow? This website saves all information displayed in the various datagrids, textboxes, etc. to an SQL database.

3) I think the third piece of code you provided goes in the main page, the second is the code for the usercontrol, but where does the first piece go?

Thanks for your help so far.
Reply With Quote
  #8  
Old 04-01-2008, 07:04 AM
Rikki Rikki is offline
Freshman
 
Join Date: Jan 2008
Location: Waterloo, ON
Posts: 47
Default

There are two pages that I need to split up. I tried separating one page entirely and doing it the same way I did the other page (it turns out user controls can't be displayed using the same method I used for the page above). It is displayed but now I have a problem with a save button, the method I am calling for it is on one of the tab pages but the actual button is outside of the tab control (on the main page). Apart from this it works well. Does anyone know how I could make the save button work?

Problem is that if I make the save method shared, several subs from the clsGlobal.vb class and from within the same class that I use, as well as controls on the .aspx page, do not work. Any ideas?
Reply With Quote
  #9  
Old 04-01-2008, 11:15 AM
MKoslof's Avatar
MKoslofHELP with accessing controls within 3rd party Tab Control tags MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

What does this save button actually do? For example, you say you have a tab page and the button lives outside of the tab page. So when you hit save what is supposed to be updated?

And you really should never used a global shared save method in a web application. Web Applications or Server apps are meant to be re-entrant and each request is processed on its own thread - - ASP.net does all this for you.

If you tab control is on the same page as the button, could you not leverage the Viewstate and then within your save button click check the view state values and update a database or whatever you are doing? And why can't the save button go within the tab page. Do you have a "Shared" save button for a particular reason - - if the save button should do an action based on controls in the tab page, why isn't within the tab page?
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #10  
Old 04-01-2008, 12:29 PM
Rikki Rikki is offline
Freshman
 
Join Date: Jan 2008
Location: Waterloo, ON
Posts: 47
Default

the save button updates an sql database or adds a new entry if it is a new company being created. The point of having the save button outside of the tab control is so that it is there regardless of active tab and so that it is always visible and the user does not have to scroll down to find it. I have been told there is no way to do this without making the save method in the behind code for the appropriate tab shared, but that would make references to other methods, controls, etc not work.

What is the viewstate and how do I use it?
Reply With Quote
  #11  
Old 04-02-2008, 11:28 AM
MKoslof's Avatar
MKoslofHELP with accessing controls within 3rd party Tab Control tags MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

OK, I assume you are new to Web development . From what I see, what you really want to do is track the page changes. This is exactly what the ViewState is for.

The ViewState is a hidden field provided to you which you can reference. It can be used in various ways, has various behavior and can be enabled or disable for a given control and page entity, etc.

Please start here:

http://msdn2.microsoft.com/en-us/library/ms972976.aspx
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #12  
Old 04-02-2008, 11:40 AM
Rikki Rikki is offline
Freshman
 
Join Date: Jan 2008
Location: Waterloo, ON
Posts: 47
Default

Thank you for your response, and yes I am just starting, this is my first project using asp.net, vb, and SQL.

A developer my supervisor knows suggested using panels with a menu instead of this (useless) tab control. Due to a tight schedule and other problems with the control I have used his suggestion, and the page is now fully operational and looks identical to the tab control. Thanks all the same though. With any luck I should be ready to put it on the server tomorrow morning!

--Rikki
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
 
HELP with accessing controls within 3rd party Tab Control tags
HELP with accessing controls within 3rd party Tab Control tags
 
-->