Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 August 11th, 2008, 05:28 PM
Registered User
 
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Iterating through the LinkButtons in a page.

Hello,

I have a User Control which comprises of some LinkButtons. I want to Iterate through each control and add some attributes to each of them.

I am using the code below to accomplish this:

Code:
        foreach (LinkButton lnk in Controls.GetEnumerator())
        {
            lnk.Attributes.Add("onMouseOver", "return statusMsg()");
            lnk.Attributes.Add("onMouseOut", "return statusClear()");
        }
However, I am getting the following error.

foreach statement cannot operate on variables of type 'System.Collections.IEnumerator' because 'System.Collections.IEnumerator' does not contain a public definition for 'GetEnumerator'

How should I provide the public definition for the GetEnumerator?

Thanks,
Nocofoolme.

 
Old August 12th, 2008, 11:37 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

have you tried?

        foreach (LinkButton lnk in Page.Controls)
        {
            lnk.Attributes.Add("onMouseOver", "return statusMsg()");
            lnk.Attributes.Add("onMouseOut", "return statusClear()");
        }


Jason Hall
 
Old August 12th, 2008, 02:52 PM
Registered User
 
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes I have tried that.

It is giving me this error.

Unable to cast object of type 'ASP.bookstore_master' to type 'System.Web.UI.WebControls.LinkButton'.

 
Old August 12th, 2008, 02:59 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

try this....

foreach (Control ctrl in Page.Controls) {
         if (ctrl is LinkButton) {
             ((LinkButton)ctrl).Attributes.Add("onMouseOver", "return statusMsg()");
             ((LinkButton)ctrl).Attributes.Add("onMouseOut", "return statusClear()");
         }
     }

Jason Hall
 
Old August 13th, 2008, 02:04 PM
Registered User
 
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jason,

I have tried that but no use. this is my code:

Code:
protected void Page_Load(object sender, EventArgs e)
      {
        IterateLinkButtons();
      }

      /// <summary>
      /// Iterates through the LinkButtons in the Nav control.
      /// </summary>
      public void IterateLinkButtons()
      {
        foreach (Control ctrl in Page.Controls)
        {
            if (ctrl is LinkButton)
            {
                ((LinkButton)(ctrl)).Attributes.Add("onMouseOver", "window.status = 'Browse Catalog'; return true;");
                ((LinkButton)(ctrl)).Attributes.Add("onMouseOut", "window.status = ''; return true;");
            }
         }
      }
--------------------------------------------------


but when I do it for individual controls like this:

LnkButton1.Attributes.Add("onMouseOver", "window.status = 'Browse Catalog'; return true;");

It is working in IE but not in firefox

 
Old August 13th, 2008, 02:09 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

What is the error you get? or is it just not working how you are expecting it to?

Jason Hall
 
Old August 13th, 2008, 02:25 PM
Registered User
 
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by alliancejhall
 What is the error you get? or is it just not working how you are expecting it to?

Jason Hall
It is just not working. I do not get any compile time errors. I heard there is issue with FF3.0 and ASP.NET. Is this true



 
Old August 13th, 2008, 02:29 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default

I'm not sure.... I don't really code in 3.5 but i do have FF 3.0 and haven't run into any strange issues
like this but I've never tried to change the window status either? maybe FF doesn't let you do that? check your
html output (right click, view page source) and see if the link buttons are actually getting the attributes added
or not.

Jason Hall
 
Old August 13th, 2008, 02:54 PM
Registered User
 
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by alliancejhall
 I'm not sure.... I don't really code in 3.5 but i do have FF 3.0 and haven't run into any strange issues
like this but I've never tried to change the window status either? maybe FF doesn't let you do that? check your
html output (right click, view page source) and see if the link buttons are actually getting the attributes added
or not.

Jason Hall
Yes, attribute got added. Here:

<a id="ctl00_Nav1_LnkCatalog" onMouseOver="window.status = 'Browse Catalog'; return true;" onMouseOut="window.status = ''; return true;" href="javascript:__doPostBack('ctl00$Nav1$LnkCatal og','')">Browse Catalog</a>


edit: But it is not showing up in the status bar
 
Old August 13th, 2008, 02:55 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi There,

Just thought I would get in on this too.. I cant seem to get the code to work properly either.. I'm not even getting a status in IE?!

Rob
http://cantgrokwontgrok.blogspot.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Iterating through DropDownBox rsearing ASP.NET 2.0 Basics 8 January 3rd, 2007 04:35 PM
filtering datalist with linkbuttons pettrer ASP.NET 2.0 Basics 0 July 8th, 2006 03:46 PM
DataGrid LinkButtons/Pushbuttons testsubject General .NET 0 June 27th, 2006 02:46 AM
Iterating Fonts Ron Howerton Visual Basic 2005 Basics 9 May 31st, 2006 07:15 PM
LinkButtons Alaric VS.NET 2002/2003 1 November 7th, 2003 01:34 AM





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