 |
| 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
|
|
|
|

August 11th, 2008, 05:28 PM
|
|
Registered User
|
|
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

August 12th, 2008, 11:37 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
|
|
have you tried?
foreach (LinkButton lnk in Page.Controls)
{
lnk.Attributes.Add("onMouseOver", "return statusMsg()");
lnk.Attributes.Add("onMouseOut", "return statusClear()");
}
Jason Hall
|
|

August 12th, 2008, 02:52 PM
|
|
Registered User
|
|
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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'.
|
|

August 12th, 2008, 02:59 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
|
|
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
|
|

August 13th, 2008, 02:04 PM
|
|
Registered User
|
|
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 13th, 2008, 02:09 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
|
|
What is the error you get? or is it just not working how you are expecting it to?
Jason Hall
|
|

August 13th, 2008, 02:25 PM
|
|
Registered User
|
|
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 13th, 2008, 02:29 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
|
|
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
|
|

August 13th, 2008, 02:54 PM
|
|
Registered User
|
|
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 13th, 2008, 02:55 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|
 |