Tuesday, June 06, 2006

LinkButton doesn't print out a name attribute

When you use a LinkButton Control in ASP.NET 1.1 there is one difference compared to a Button Control.  A LinkButton does not print out a name attribute in the Generated HTML.

I was trying to write some javascript from a textbox to press the LinkButton if the enter key is pressed as this is not done automatically in .NET.

I was having the worst time debugging this stipping it all down to bare javascript calls. But I kept coming up with this.form.elements.somenameattibute has no properties.  Obviously I was getting at the LinkButton control but for some reason could not figure out why.  I switched over to document.getElementById("someIDattribute").click() and this worked great in IE but did not work in Firefox.  So back to debugging I went.

After looking at the code and the example code that I lifted this with I noticed that the code had a name attibute and my code did not.  I switch my Link button over to a button control and everything worked fine.

So in case you need to know this information at a later time a LinkButton control does not print out a name attribute, at least by default.

Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):

Blog Posts by:

Currently Viewable:

My Twitter Updates

View Twitter Page