Stopping IE from highlighting the first submit-button in a form - asp.net

The expected behaviour on enter in a form seems to be undefined in the HTML 4.01 Specification while the HTML 5 specification says it should be the first submit button in the form.
Internet Explorer (IE) highlights the first button in the form when the form has focus by adding a proprietary border or something. Other browsers do not add such a visual clue.
I'd like to use another button as the default and style this button so all browsers will provide a visual clue that it is the default button. (We're using ASP.NET which uses one form per page, and so it's hard to design the pages so that the default button always comes first.)
While I can easily accomplish this with javascript and css in most browsers, I'm having trouble making IE stop highlighting the first button.
Is there any way to tell IE to NOT highlight the first submit-button or to highlight a different button? Or is there some other solution that I've missed?

On your asp.net button control, set useSubmitBehavior="false". That renders the html as a button rather than a submit.

ASP.Net 2.0 also introduced the concept of DefaultButton.
This is available on atleast Form and Panel elements:
<form id="form1" runat="server" defaultbutton="Button2">
<div>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button id="Button1" runat="server" text="1st Button" onclick="Button1_Click" />
<br />
<br />
<asp:panel id="something" defaultbutton="button3" runat="server">
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button id="Button2" runat="server" text="2nd Button" onclick="Button2_Click" />
<br />
<asp:Button id="Button3" runat="server" text="3rd Button" onclick="Button3_Click" />
</asp:panel>
<br />
<br />
</div>
</form>
So, when you load the page, or are entering text in TextBox1, pressing Enter will submit Button2. When you are entering text in TextBox2 pressing Enter will submit Button3 - as you are inside the Panel.
This is powered by an onkeypress method created by ASP.Net.
When the page loads, IE and Firefox both highlight Button2 (as you want).
If you know which button will be declared as the defaultbutton, you can use what ever CSS you would normally use to style this for all browsers.
Rather annoyingly, when you focus either text box, IE will then (incorrectly) highlight Button1.
This is because IE's default behaviour is overridden by some javascript emitted by ASP.Net:
<script type="text/javascript">
//<![CDATA[
WebForm_AutoFocus('Button2');//]]>
</script>
But, IE will then ignore that once another element has focus, and go back to highlighting the wrong button (which doesn't get used unless the user explicitly clicks it in this example).
Other than replacing them with image buttons, I'm not sure what else I can suggest.

One way to get around this is to create a dummy button at the top of the form and move it out of sight. Then handle the enter keycode in javascript and style the new default button with css.
Feels dirty though. Any better ideas?

Use either of these CSS Styles
a:active, a:focus,input, input:active, input:focus{ outline: 0; outline-style:none; outline-width:0; }
a:active, a:focus,button::-moz-focus-inner, input[type="reset"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner, input[type="submit"]::-moz-focus-inner, input[type="file"] > input[type="button"]::-moz-focus-inner
{ border: none; }
OR
:focus {outline:none;} ::-moz-focus-inner {border:0;}
Once the CSS Style part is done, then you might also need to set the IE-Emulator. Update your web applications web.config file and include below key.
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=7; IE=9; IE=8; IE=5;" />
</customHeaders>
</httpProtocol>
</system.webServer>

If you are using .Net 2 this may help you
...Use the DefaultFocus property to
access the control on the form to
display as the control with input
focus when the HtmlForm control is
loaded. Controls that can be selected
are displayed with a visual cue
indicating that they have the focus.
For example, a TextBox control with
focus is displayed with the insertion
point positioned inside of it. ...

What about defining a particular CSS style (or class) for this button ?
<input type="button" value="basic button" .../>
<input type="button" style="border: solid 2px red;" value="default button" .../>

Related

How to Style a Disabled ASP.NET Buttons

I have an asp button that I am styling using CSS.
Button:
<asp:Button ID="btnClockin" runat="server" Text="Clock In" class="FullWidthButton" />
CSS:
.FullWidthButton {width:100%;}
This works fine until I set btnClockIn.Enabled = False in my code, then it doesn't pick up the style. I tried adding the following CSS.
.FullWidthButton[disabled="disabled"]{width:100%;}
and
.FullWidthButton[disabled]{width:100%;}
but these don't seem to have any effect. What am I doing wrong?
Change "class" to "CssClass" and it should work consistently.
You can use this its works for me:
<asp:Button ID="btnClockin" runat="server" Text="Clock In" style="width=100%" />

Textbox Width Problems - ASP.NET

I have a user control on a page of a website that generates a text box. The textbox has a width specified, but the text box is intermitently being shown at a much smaller width than is specified in the code. I asked the users to send me copies of the "view source" output so that I could compare good and bad results. By "intermittent", I mean similar builds - different computers. Please note that the bad results are ALWAYS displayed on the same "bad" computers (there is more than one user with this problem) and, conversely, the "good" computers (all with the same version of IE7 as the "bad" computers) always display "good" results.
When the page is displayed correctly, the html that is sent to the browser looks like this:
<input name="ShortDescription" type="text" maxlength="100"
id="ShortDescription" class="content" style="width:800px;" />
and when it renders incorrectly, it looks like this:
<input name="ShortDescription" type="text" maxlength="100"
id="ShortDescription" class="content" />
In both cases, the ASP.NET code is:
<asp:textbox id="ShortDescription" runat="server"
CssClass="content" Width="800px" MaxLength="100"> </asp:textbox>
I am not sure why the style tag is getting dropped. The above pages were both viewed in the same browser (IE7) on different computers. The computers have a corporate build so they "should" be configured the same.
I would appreciate any help!
Try setting the TextBox with in the CssClass, or as a style attribute parameter rather than using the Width attribute
<asp:TextBox id="ShortDescription" runat="server" CssClass="content" MaxLength="100" style="width: 800px" />
<style>.content { width: 800px }&lt/style>
<asp:TextBox id="ShortDescription" runat="server" CssClass="content" MaxLength="100" />
Apply the min-width property.
In Your CSS Style Sheet
.Textbox
{
min-width:100%;
}
In Your *.aspx
<asp:TextBox CssClass="TextboxStyle" placeholder="Enter the Title" runat="server" ID="TextBox1"></asp:TextBox>
This will update your text box
In the past I've found that setting the width through your class itself, instead of using the width property of the textbox will make sure the control is rendered properly.
asp:textbox, which compiles to an input tag does not have a "width" attribute according to w3. It supports the "size" attribute. IE(678) would probably have a better time with the standard, where as other browsers are... looser in their interpretation.
http://www.w3.org/MarkUp/1995-archive/Elements/INPUT.html
for fix the width of text box
take one skin file and put the below code...
for example "skinFile.skin"
<textbox runat="server" width="200px"/>
......................................
after that put the following code into your aspx page.
Theme="SkinFile
for example...
<%# Page Language="C#" MasterPageFile="~/AdminMaster.master" AutoEventWireup="true" CodeFile="stu_resgistration.aspx.cs" Inherits="AdminSide_stu_resgistration" Title="Untitled Page" Theme="SkinFile"%>

Hide the html contorl from the server side without using attributes runat="Server"

I am using HTML control,and want to visible false from the server side with out using attributes runat="Server"
tell me any solution
Runat="Server" has got nothing to do with visibility.
If you want to hide the control (so that its not visible to any visitors to your site) you would simply set its CSS to visibility:hidden; or display: none;. I think this is what you wanted to know.
Wrap your html controls in an asp:placeholder control, and set the visibility on the placeholder.
Example
<asp:placeholder id="plc" runat="server" visible="false">
<h1>Some Content</h1>
<img src="/images/someimage.gif" alt="" />
</asp:placeholder>

Controlling the appearance of disabled pagination links (a[disabled="disabled"]) rendered by a DataPager

I have a datapager with next and previous buttons as so:
<asp:DataPager ID="dpFeaturedPager" PagedControlID="lvFeaturedTips" QueryStringField="ftpg" PageSize="1" runat="server">
<Fields>
<asp:nextpreviouspagerfield ButtonCssClass="featured-previous" PreviousPageText="Previous" ShowNextPageButton="false" />
<asp:nextpreviouspagerfield ButtonCssClass="featured-next" NextPageText="Next" ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
When there is only one page available, the Next and Previous links are rendered as so:
<a disabled="disabled">Previous</a>
I have not seen this disabled tag before, and presume it's coming from the datapager control which I won't be able to control.
As usual, this is fine on FireFox but on IE7 the Previous and Next text does not render correctly - it is outlined (what I would expect disabled to look like to be honest - but looks a bit ugly in the page!)
Can I control this in CSS, or is this a known issue?
Thanks
Duncan
Check out this thread on StackOverflow, they have some suggestions on CSS styling for disabled links and controls. Hope it helps!
a[disabled=disabled] {
color: red;
font-weight: bold;
border: 0px;
}
Edit: Doesn't look like the selector attribute will work in IE6.
You cannot set color of disabled control in IE. You can change background or border, but the color will always stay gray with white shadow (system color). It does not work even in IE9.
Thread about this issue: How to change color of disabled html controls in IE8 using css.
Quick solution using jQuery removeAttr():
$('a').removeAttr('disabled');
This:
<a disabled="disabled">Sad</a>
Becomes This:
<a>Happy</a>
I added a class of 'btnDisable' to both the next and previous links then used CSS...
span .btnDisable {cursor: not-allowed; }
span a.btnDisable {cursor: pointer; }
Just make sure you set RenderDisabledButtonsAsLabels to True.
For those that still look for this issue, from .net 4.0 you have the possibility to define in the web.config file the HTML compatibility for .net controls.
<pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID">
Then in the Global.asax.cs you can specify the CSS class .net should apply to disabled controls.
System.Web.UI.WebControls.WebControl.DisabledCssClass = "disabled";

Weird spacing of Checkbox labels

when I try to create a number of Checkboxes, I have strange spaces inserted:
image
<td style="width:85%;white-space:nowrap;" colspan=3>
<asp:CheckBox ID="rdoSchool" runat="server" Text="School (NSL)" />
<asp:CheckBox ID="rdoSFS" runat="server" Text="Summer Food Service" />
<asp:CheckBox ID="rdoOther" runat="server" Text="Other (Specify)" />&nbsp<asp:TextBox ID="txtOther" Width="125px" runat="server" />
</td>
How can I make the label closer to the checkbox?
This isn't default styling, and is most likely caused by your CSS. Use a tool like Firebug (on Firefox) or Developer Tools on IE8 to find the applied CSS rules (Should be F12 either way).
Take a look at the markup the CheckBox control generates.
... "Now there's your problem" - Adam Savage, Mythbusters.
Basically the CheckBox control (along with the RadioButtonList control) generates crappy markup. One way to fix this, is to extend and override the Render method to implement some sensible markup-generation code. Another option is to force the HTML-tables the control generates into place with some clever CSS tricks.

Resources