Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > SetFocusOnError

Reply
Thread Tools

SetFocusOnError

 
 
Shooter
Guest
Posts: n/a
 
      07-16-2007
Hi,

I'm having problems getting validation controls to set the focus back to the
textbox that caused the error (or any error). Using ASP.Net 2 and IE 6.

Does anyone have a solution to help me out on this one? Heres some code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" />

<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
SetFocusOnError="true"
ErrorMessage="TextBox1 is empty" ControlToValidate="TextBox1"
runat="server"/><br />
<asp:TextBox ID="TextBox2" runat="server" />

<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
SetFocusOnError="true"
ErrorMessage="TextBox2 is empty" ControlToValidate="TextBox2"
runat="server"/>
<br />
<asp:Button ID="Button1" runat="server" Text="Button"
CausesValidation="true"/>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
ShowMessageBox="True"
ShowSummary="False" />
</div>
</form>
</body>
</html>

 
Reply With Quote
 
 
 
 
Shooter
Guest
Posts: n/a
 
      07-24-2007
Hi timmy123,

I tried this on my laptop and home and found it also worked so I'm putting
it down to either differing versions of IE or maybe something that occurred
with the conversion of this project from 1.1 to 2.0 via the wizard.

It maybe the conversion as the page I copied the code from had a demo of it
and it was working ok in the same IE ver here at work.

"timmy123 via DotNetMonster.com" wrote:

> Hi,
>
>
> The Focus API allows you to declaratively or programmatically set focus to
> specific controls on the form. You can use the Page.SetFocus method to pass
> the ID of a control that should receive focus or you can call the Focus
> method on the control directly. You can also set the DefaultFocus property of
> the Form element to the ID of a control that should receive focus when the
> page is first loaded. Similar to DefaultFocus, you can set the DefaultButton
> property of the Form element to the ID of a Button control that should submit
> when the Enter key is pressed inside of any input control on the form. If
> your page should have different default buttons depending on the input
> control that has current focus, you can wrap specific input controls in a
> Panel control and set the DefaultButton property of the Panel instead. Any
> input control in the Panel will use the Panel's DefaultButton property to
> submit the form when the Enter key is pressed from within the input control.
> A validation feature that depends on the Focus API is SetFocusOnError which
> is set on validator controls to cause the first invalid control to receive
> focus.
>
> Page.SetFocus(TextBox1);
>
>
> I tried your code. It is working for me. Any questions, please post it again.
>
> Database programming using Visual Basic 2005 and Csharp2005
> http://www.vkinfotek.com
>
>
>
>
>
> Shooter wrote:
> >Hi,
> >
> >I'm having problems getting validation controls to set the focus back to the
> >textbox that caused the error (or any error). Using ASP.Net 2 and IE 6.
> >
> >Does anyone have a solution to help me out on this one? Heres some code:
> >
> ><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
> >Inherits="WebForm1" %>
> >
> ><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> >"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> >
> ><html xmlns="http://www.w3.org/1999/xhtml" >
> ><head runat="server">
> > <title>Untitled Page</title>
> ></head>
> ><body>
> > <form id="form1" runat="server">
> > <div>
> > <asp:TextBox ID="TextBox1" runat="server" />
> >
> ><asp:RequiredFieldValidator ID="RequiredFieldValidator1"
> > SetFocusOnError="true"
> > ErrorMessage="TextBox1 is empty" ControlToValidate="TextBox1"
> >runat="server"/><br />
> ><asp:TextBox ID="TextBox2" runat="server" />
> >
> ><asp:RequiredFieldValidator ID="RequiredFieldValidator2"
> > SetFocusOnError="true"
> > ErrorMessage="TextBox2 is empty" ControlToValidate="TextBox2"
> >runat="server"/>
> > <br />
> > <asp:Button ID="Button1" runat="server" Text="Button"
> >CausesValidation="true"/>
> > <asp:ValidationSummary ID="ValidationSummary1" runat="server"
> >ShowMessageBox="True"
> > ShowSummary="False" />
> > </div>
> > </form>
> ></body>
> ></html>

>
> --
> Message posted via DotNetMonster.com
> http://www.dotnetmonster.com/Uwe/For...trols/200707/1
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SetFocusOnError Validation Lit ASP .Net 0 08-25-2007 06:44 PM
setfocusonerror Boudewijn ASP .Net Web Controls 0 08-17-2006 07:56 PM



Advertisments