The replacement to the name attribute - iframe

I am confused. I need to name my iframe in order to use the name as the target in my menu's hypelinks. According to my Visual Web Developer Express the name attribute is considered outdated and a new construct is required. My question is what attrbute code do I utilize to name my iframe. Thank you

According to my Visual Web Developer Express the name attribute is considered outdated and a new construct is required.
Then Visual Web Developer Express is wrong. For the purposes of anchors and scripting/styling hooks, 'name' is to be replaced by 'id', but for the purpose of identifying link targets (such as frames), it is not. See http://www.w3.org/TR/REC-html40/present/frames.html#adef-target , http://www.w3.org/TR/REC-html40/present/frames.html#adef-name-IFRAME .
This usage is not deprecated in HTML terms, but it's a bit of a code smell. Targeting a link to an iframe is generally considered a bad thing as it breaks many normal navigational expectations. There are uses for it, but be wary.

Ignore the warning. Believe the DOCTYPE specification. The name attribute is just fine. In fact, HTTP posts via embedded HTML forms pass data using the name attribute as the key.
<input id="txtName" name="name" />
To get at the textbox value in your Page_Load, you would use Request.Form("name"), and not Request.Form("txtName")
When in doubt about attributes and such, run your rendered HTML through the W3 validator to validate it against the DOCTYPE.

Typically, you would use the "id" attribute as a replacement. This is not always "optimal". I have noticed that this does not always work for named anchors, for instance.

Related

Which Seam component to use: <h:outputLink> or <h:commandLink>?

I'm very new to Seam and am just getting used to the different components available. I'm wondering which one I should use for this situation.
The answer to this question explains the difference between <h:outputLink> and <h:commandLink>, that <h:outputLink> produces just a basic HTML link tag with GET request and <h:commandLink> submits a POST via a click event.
I just want to attach a simple jQuery click event to a link. I don't want the link to redirect to anywhere or submit a form. I basically want the equivalent of href="#" (I understand that commandLink generates href="#" but it seems heavy-handed for a simple link with no form submission). But <h:outputLink> implicitly adds an href value unless I put value="#" (which seems hacky).
What component do I want to use here? I seem to be missing some very basic element.
(First: <h:outputLink> and <h:commandLink> are standard JSF components, not part of the Seam framework.) In this case, you can just use the standard HTML tag <a>, because you appear not to be using anything special to JSF.

setting Style property of a WebControl From Code Behind

recently I found in one of my older projects (asp.net 4.0)
that I've been using this code
to set display Style-property To none
DDL_ChosenEmpl.Attributes.Add("style", "display:none");
lately I was using
DDL_ChosenEmpl.Style.Add("display", "none");
i would like to know
in any case such as - property already exist whether it's with different value or not , will any of them should be avoided ?
what are the main differences between both methods ?
Both does the same functionality as you have done. The thing is, in "Attributes" collection, you have a control's other attributes like "click", "dblclick", etc. You can use either way. I believe Microsoft has given the later part for user's convinience to make coding easy.

Is it bad to add a css class that doesn't exist?

I want to add a bunch of classes to some text fields so i can get their values with jquery. This seems like standard practice when using jQuery and this post suggests it as the answer but how does this affect page loading? Won't it be trying to find all these classes? I have been told in the past to try minimise the amount of classes used on controls.
I have about 12 controls i'll want to add unique classes to to get their value. I am using asp.net so I can't use the id. I also can't use the ClientID as the controls are in a table (but only 1 set of controls will show at any one time).
e.g.
<asp:TextBox ID="txtValue1" runat="server" CssClass="value1" Text='value1' />
<asp:TextBox ID="txtValue2" runat="server" CssClass="value2" Text='value2' />
<asp:TextBox ID="txtValue3" runat="server" CssClass="value3" Text='value3' />
...
var value1 = $('.value1').val();
var value2 = $('.value2').val();
var value3 = $('.value3').val();
And none of the class names will exist in css.
Thanks
Edit:
I know this works but I was more curious about the affect it had on page loading. There was an answer (seems to be deleted now) that said something like the html parser ignores the classes. The css parser will only look at classes that are defined. So it sounds like it would be completely ignored and have no affect on page load. Is this right?
It is okay to use a CSS class that doesn't exist, but if they are unique you want to use id, not class.
You say you are using ASP.Net so you can't use the ID parameter, but you can. In JQuery you can get the controls using the below
var value1 = $('[ID$=yourID]').val();
For more info on JQuery Selectors check out: JQuery Selectors and Attribute Ends With Selector
The above selector basically finds the id ENDING in "yourID" so ignoring all the masterpages extra text at the start. You just have to make sure these are unique. e.g. don't have ids like "HSBC" and "SBC" as the above selector on "SBC" will find both.
I don't think it's a problem. The only times I've had problems with non-existant classes or ID's is one time I had an onclick reference an ID that didn't exist. This messed things up...Other than that I think classes are pretty harmless. I'd be interested to know though..
Any other thoughts??
Which version of asp.net are you using? In asp.net 4.0, you have the ability to use unmangled ids. It looks like the simplest solution would be to set ClientIDMode="Static" to all of your textboxes and then refer by id. Otherwise, sure, I've created classes that don't exist to refer to things.... all the time.
Edit: (in response to your comment about the effect page load).
I think your question about having extra classes in a div that are not currently used is not a bad question (at least in a theoretical sense), and I honestly don't know the precise answer. I do believe any effect is quite minuscule. If you consider best practices to write html, you generally write and structure the HTML, with it's classes, before you write the CSS. This means at the time you write the CSS, certainly some classes will not be used. Indeed, after styling the basic tags (body, h1, a, etc), you may find you never need to create selectors with those classes for some particular design. And yet for the next design, you might need those classes. I'm pretty sure the technology behind CSS was built with those kinds of scenarios in mind, and I bet millions if not billions of pages on the internet follow that exact scenario, especially if they use something like Modernizr, which adds classes to the html element of the page as a way of providing you classes you can select against considering the possible capabilities of the current browser. You may never need those classes, but they are there if you need them.

Reason why html id attribute is uppercase generated in ASP.NET?

I am quite new to ASP.NET. When creating new pages that already contain ASP.NET components the id attribute is generated in upper case, for other elements the id attribute is generated in lower case:
<asp:xxx ID="foo" ...>
vs.
<div id="blaa" ...>
I am wondering what the reason for that is. I would tend to use lower case in both cases - is that ok? Can someone please shade some light on this?
Many thanks!
When you use <asp:xxx the attribute names have to match the properties of control class xxx.
Microsoft naming convention is that 2 letter acronyms are upper case, so the property name is ID.
Any other property name longer than 2 letters will be CamelCase.
The server will parse the <asp:xxx tag, so the result HTML might look very different.
Alternatively <div is HTML and will be all lowercase. The server will just serve it up as it is in your page.
That is just the ASP.NET syntax of Visual Studio changing to be uppercase. When you look at the actual generated HTML it will be lowercase just like the rest of your HTML.
You can do either, but the "Auto Generated" stuff or auto corrected stuff will have ID.

Testing ASP.NET sites using master pages with Selenium

What is a good approach to avoiding Selenium tests being broken when dealing with the changing "Name" and "Id" attributes of a control that is rendered on a ASP.NET page using a master page? I want to avoid changing my tests when ASP.NET renders the web page's controls with different DOM identifiers.
http://www.stevetrefethen.com/blog/AutomatedTestingOfASPNETWebApplicationsUsingSelenium.aspx
Selenium
solves this problem using XPATH and
providing the ability to locate
controls based on XPATH expressions,
alleviating the need to hard code HTML
tag structure into a test script. For
example, the ASP.NET runtime may
render ID attributes that look like:
id="ctl00_cphContents_gridMaint_DataGrid"
Finding this control using an XPATH
expression can be simplified to
something like this:
table[contains(#id, "gridMaint")]
In the event the nesting of the
DataGrid changes the script will
continue to function properly as long
as table's ID contains the text
"gridMaint".
Another option is to use CSS locators. They're normally less fragile than XPath. For example, to target a div with a class of .myDiv you can use the locator "css=.myDiv". If the specified element has other classes the CSS locator will still work, although the XPath equivalent would change from "//div[#class='myDiv']" to "//div[contains(#class, 'myDiv']". Also, CSS locators tend to be faster than XPath across browsers.

Resources