By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

Set focus on the field (Form validation in ASP.NET)

P: n/a
Hi,

I have a problem and really need your help. In my web page ASPX, I have
some text fields to accept data from users. I did form validation like this
:

<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION: absolute"
runat="server" Width="107px" BorderColor="Transparent"
autoPostback="true"
OnTextChanged="txtFUEL_ISSUED1_TextChanged"></asp:TextBox>
</td>

<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:CompareValidator id="CompareValidator1"
runat="server" Width="90px" ControlToValidate="txtFUEL_ISSUED1"
ForeColor="LightCoral" ErrorMessage="Please enter a number!"
Operator="DataTypeCheck" Type="Double"></asp:CompareValidator>
</td>
In the txtFUEL_ISSUED1_TextChanged, I checked if data on this field is valid
or not. If it's valid then I add this value in the TOTAL field. I'd to to
set focus on the next field when this data IS VALID, OR focus on this field
when data IS NOT valid . Can you help me ? Thanks in advance
Dec 1 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I suggest you upgrade to ASP.NET 2.0, which has new features that satisfy
all your requests.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"bienwell" <bi******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi,

I have a problem and really need your help. In my web page ASPX, I have
some text fields to accept data from users. I did form validation like
this :

<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION:
absolute" runat="server" Width="107px" BorderColor="Transparent"
autoPostback="true"
OnTextChanged="txtFUEL_ISSUED1_TextChanged"></asp:TextBox>
</td>

<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:CompareValidator id="CompareValidator1"
runat="server" Width="90px" ControlToValidate="txtFUEL_ISSUED1"
ForeColor="LightCoral" ErrorMessage="Please enter a number!"
Operator="DataTypeCheck" Type="Double"></asp:CompareValidator>
</td>
In the txtFUEL_ISSUED1_TextChanged, I checked if data on this field is
valid or not. If it's valid then I add this value in the TOTAL field. I'd
to to set focus on the next field when this data IS VALID, OR focus on
this field when data IS NOT valid . Can you help me ? Thanks in advance

Dec 2 '05 #2

P: n/a
Steve,

I have some questions:

1- There are some versions ASP.NET 2.0 from the www.asp.net web site :
a- .NET Framework 2.0 SDK x86,
b- .NET Framework Version 2.0 Redistributable Package (x86)
c- .NET Framework 2.0 SDK x64
d- .NET Framework Version 2.0 Redistributable Package x64 (64
Bit)
e- .NET Framework 2.0 SDK IA64
f- .NET Framework Version 2.0 Redistributable Package IA64
(64 Bit)

Which one do you suggest me to download ?

2- After downloading, do you think this code will work OR I should
change something ?

Sub txtFUEL_ISSUED1_TextChanged(sender As Object, e As EventArgs)
Dim strScript As String = "<script language=JavaScript>"

If IsNumeric(txtFUEL_ISSUED1.text) OR
txtFUEL_ISSUED1.text="" Then
Dim aValue as double=0.0
If IsNumeric(txtFUEL_ISSUED1.text) Then
aValue=CDBL(txtFUEL_ISSUED1.Text)
End If

' ADD the value to the TOTAL field
ViewState("FUEL_ISSUED_Total") =
ViewState("FUEL_ISSUED_Total") + aValue - ViewState("FUEL_ISSUED1")
txtFUEL_ISSUED_Total.text=FormatNumber(ViewState(" FUEL_ISSUED_Total"),
2, , ,TriState.True)
ViewState("FUEL_ISSUED1") = aValue

strScript = strScript &
"document.form1.txtFUEL_ISSUED2.focus();" 'FOCUS on the next field

Else 'FOCUS on the current field
strScript = strScript &
"document.form1.txtFUEL_ISSUED1.focus();"
End If

strScript = strScript & "<" & "/script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If

End Sub

================================================== =
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I suggest you upgrade to ASP.NET 2.0, which has new features that satisfy
all your requests.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"bienwell" <bi******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi,

I have a problem and really need your help. In my web page ASPX, I have
some text fields to accept data from users. I did form validation like
this :

<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION:
absolute" runat="server" Width="107px" BorderColor="Transparent"
autoPostback="true"
OnTextChanged="txtFUEL_ISSUED1_TextChanged"></asp:TextBox>
</td>

<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:CompareValidator id="CompareValidator1"
runat="server" Width="90px" ControlToValidate="txtFUEL_ISSUED1"
ForeColor="LightCoral" ErrorMessage="Please enter a number!"
Operator="DataTypeCheck" Type="Double"></asp:CompareValidator>
</td>
In the txtFUEL_ISSUED1_TextChanged, I checked if data on this field is
valid or not. If it's valid then I add this value in the TOTAL field. I'd
to to set focus on the next field when this data IS VALID, OR focus on
this field when data IS NOT valid . Can you help me ? Thanks in advance


Dec 2 '05 #3

P: n/a
If you have a 32-bit machine ( a standard Intel or AMD )...

If you want the very minimum necessary to run ASP.NET 2.0,
get .NET Framework Version 2.0 Redistributable Package (x86)
If you want the QuickStart Tutorials, extra tools *and* ASP.NET 2.0,
get .NET Framework 2.0 SDK x86

If you have a 64-bit machine, your choice may vary depending on the cpu.

The code you posted should run on any of the 5 choices.

Juan T. Llibre
ASP.NET.FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================

"bienwell" <bi******@hotmail.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Steve,

I have some questions:

1- There are some versions ASP.NET 2.0 from the www.asp.net web site :
a- .NET Framework 2.0 SDK x86,
b- .NET Framework Version 2.0 Redistributable Package (x86)
c- .NET Framework 2.0 SDK x64
d- .NET Framework Version 2.0 Redistributable Package x64 (64 Bit)
e- .NET Framework 2.0 SDK IA64
f- .NET Framework Version 2.0 Redistributable Package IA64 (64 Bit)

Which one do you suggest me to download ?

2- After downloading, do you think this code will work OR I should change something ?

Sub txtFUEL_ISSUED1_TextChanged(sender As Object, e As EventArgs)
Dim strScript As String = "<script language=JavaScript>"

If IsNumeric(txtFUEL_ISSUED1.text) OR txtFUEL_ISSUED1.text="" Then
Dim aValue as double=0.0
If IsNumeric(txtFUEL_ISSUED1.text) Then
aValue=CDBL(txtFUEL_ISSUED1.Text)
End If

' ADD the value to the TOTAL field
ViewState("FUEL_ISSUED_Total") = ViewState("FUEL_ISSUED_Total") + aValue -
ViewState("FUEL_ISSUED1")
txtFUEL_ISSUED_Total.text=FormatNumber(ViewState(" FUEL_ISSUED_Total"), 2, ,
,TriState.True)
ViewState("FUEL_ISSUED1") = aValue

strScript = strScript & "document.form1.txtFUEL_ISSUED2.focus();"
'FOCUS on the next field

Else 'FOCUS on the current field
strScript = strScript & "document.form1.txtFUEL_ISSUED1.focus();"
End If

strScript = strScript & "<" & "/script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If

End Sub
================================================== = "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I suggest you upgrade to ASP.NET 2.0, which has new features that satisfy all your requests.


Dec 2 '05 #4

P: n/a
Thank you very much for your advices.

bienwell
==============================
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:eZ*************@TK2MSFTNGP09.phx.gbl...
If you have a 32-bit machine ( a standard Intel or AMD )...

If you want the very minimum necessary to run ASP.NET 2.0,
get .NET Framework Version 2.0 Redistributable Package (x86)
If you want the QuickStart Tutorials, extra tools *and* ASP.NET 2.0,
get .NET Framework 2.0 SDK x86

If you have a 64-bit machine, your choice may vary depending on the cpu.

The code you posted should run on any of the 5 choices.

Juan T. Llibre
ASP.NET.FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================

"bienwell" <bi******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Steve,

I have some questions:

1- There are some versions ASP.NET 2.0 from the www.asp.net web site
:
a- .NET Framework 2.0 SDK x86,
b- .NET Framework Version 2.0 Redistributable Package (x86)
c- .NET Framework 2.0 SDK x64
d- .NET Framework Version 2.0 Redistributable Package x64
(64 Bit)
e- .NET Framework 2.0 SDK IA64
f- .NET Framework Version 2.0 Redistributable Package IA64
(64 Bit)

Which one do you suggest me to download ?

2- After downloading, do you think this code will work OR I should
change something ?

Sub txtFUEL_ISSUED1_TextChanged(sender As Object, e As EventArgs)
Dim strScript As String = "<script language=JavaScript>"

If IsNumeric(txtFUEL_ISSUED1.text) OR
txtFUEL_ISSUED1.text="" Then
Dim aValue as double=0.0
If IsNumeric(txtFUEL_ISSUED1.text) Then
aValue=CDBL(txtFUEL_ISSUED1.Text)
End If

' ADD the value to the TOTAL field
ViewState("FUEL_ISSUED_Total") =
ViewState("FUEL_ISSUED_Total") + aValue - ViewState("FUEL_ISSUED1")

txtFUEL_ISSUED_Total.text=FormatNumber(ViewState(" FUEL_ISSUED_Total"), 2,
, ,TriState.True)
ViewState("FUEL_ISSUED1") = aValue

strScript = strScript &
"document.form1.txtFUEL_ISSUED2.focus();" 'FOCUS on the next field

Else 'FOCUS on the current field
strScript = strScript &
"document.form1.txtFUEL_ISSUED1.focus();"
End If

strScript = strScript & "<" & "/script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript",
strScript)
End If

End Sub
================================================== =

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I suggest you upgrade to ASP.NET 2.0, which has new features that satisfy
all your requests.


Dec 2 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.