473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

value of textboxes in browser does not match what is in viewsource ?

I have a textbox control (for simplicity call it Text1) with
autopostback turned on.

It has a couple validators:
RequiredFieldValidator_Text1
RegularExpressionValidator_Text1

The Text1 onchange (see code below) event does these things

1. fires the validators

2. if Text1 is valid,

A) re-calculates some other fields
(say Text4 and Text5)

B) set focus to Text2

3. if Text1 is NOT valid, keep focus on Text1
(and validators display their errors to the user)

The set focus is not working at all.

To set focus, originally I tried both registerstartupscript and
registerclientsidescript and neither worked. However javascript eval
seems to work:

In the HTML, i have:

<body onload="javascript:window.history.go(1);
eval(document.Form1.txtJavascript.value);">
<form id="Form1" method="post" runat="server">
<INPUT id="txtJavascript" type="hidden" runat="server"
NAME="txtJavascript">

then I init the javascript in Page_Load of the codebehind:

if not (IsPostBack) then
' SET FOCUS ON FIRST CONTROL
txtJavascript.Value = "document.Form1." & Text1.UniqueID &
".focus();"
txtTest.Value = "document.Form1." & Text1.UniqueID & ".focus();" '
for testing
end if

this works fine to set the focus to the right control the first time
the form loads.

Now in my Text1 onchange event, i simply should be able to set the
value of txtJavascript to set focus to the proper control depending on
what happens, but it doesn't work.

View source shows that the value of txtJavascript is still the same as
when it was initialized in Page_Load.

So I did a little test to see if the onchange was even changing the
text, so I had it update a visible textbox txtTest to see if anything
changed.

In the browser I see in txtTest that the value IS changed to the new
control:
document.Form1.Text2.focus();

However when I look at the codebehind, txtTest has the old value!
document.Form1.Text1.focus();

So it seems that .NET is somehow changing what is SEEN in the textbox
in the browser, but the source (and what Javascript can see) is not
changed.

Does this make any sense? Can someone help explain what's happening?

-----

'onchange event for Text1:

Private Sub Text1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Text1.TextChanged

'TEST CHANGE CONTENTS OF THE HIDDEN JAVASCRIPT BOX
txtJavascript.Value = "document.Form1." & Text2.UniqueID &
".focus();"

'TEST CHANGE CONTENTS OF A VISIBLE TEXT BOX
'JUST TO SEE IF THIS CODE IS CHANGING THE TEXT!
TextTest.Text = "document.Form1." & Text2.UniqueID & ".focus();"

' -----------------------------------------------------------------------------
' VALIDATE THE CONTROL
' so any error messages appear on the screen,
' (otherwise with autopostback, if there is a validation error,
' the messages appear for a second but then disappear
' after the autopostback re-renders the page)
RequiredFieldValidator_Text1.Validate()
RegularExpressionValidator_Text1.Validate()

' -----------------------------------------------------------------------------
' SET FOCUS DEPENDING ON VALIDATION
If RequiredFieldValidator_txtSecondaryAmount.IsValid And
RegularExpressionValidator_txtSecondaryAmount.IsVa lid Then
' CALCULATE SOME FIELDS BASED ON NEW Text1 VALUE
Call subRecalculate(Text1.text, Text4.text, Text5.text)
' GOTO NEXT CONTROL
txtJavascript.Value = "document.Form1." & Text2.UniqueID &
".focus();"
Else
' STAY AT SAME CONTROL
txtJavascript.Value = "document.Form1." & Text1.UniqueID &
".focus();"
End If

End Sub ' Text1_TextChanged
Nov 18 '05 #1
1 1730
I found a simple workaround. By adding an onchange attribute to a
control, you can force focus to the next control:

dim sJS as string
sJS = "document.Form1." & DropDownList1.UniqueID & ".focus();"
Text1.Attributes.Add("onchange", sJS)

This works if the next control you want to set focus to is a
dropdownlist, but for some reason, if the next control is a textbox:

dim sJS as string
sJS = "document.Form1." & Text2.UniqueID & ".focus();"
Text1.Attributes.Add("onchange", sJS)

when the focus gets set to it you can't type in it. However if you
tab, it tabs correctly to the next control after that. So it is sort
of receiving the focus but not really. When it renders the page .NET
adds a "dopostback" to the onchange javascript. When you view source,
the onchange property is:

onchange="javascript:document.Form1.Text2.focus(); __doPostBack('Text1','')"

I think the doPostBack is interfering with the focus command. If I
could somehow specify for my focus command to appear in the onchange
property AFTER the doPostBack, it might work. If anyone can tell me
how to do this, it would be most appreciated.
Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robin Lewis | last post by:
I have a simple Access database set up and a form and I need to compare two textboxes, 'email1' and 'email2', on the form. If the two textboxes do NOT match I need to change the background colour...
7
by: Daniel Jung | last post by:
Hi ======== Problem: ======== I want images in table rows connect vertically. All images are 32 px in height. =====
17
by: lawrence | last post by:
How is it possible that the question "How do I detect which browser the user has" is missing from this FAQ: http://www.faqts.com/knowledge_base/index.phtml/fid/125 and is only here on this...
1
by: Luis Esteban Valencia | last post by:
Hello. I have a datagird with textboxes on a column item template, I also have 2 other columns that are hidden and I want to retrieve his value. But I havent found how to do it. Thanks very much...
2
by: Nathan Sokalski | last post by:
I have a form, and when the form does a PostBack (I have several areas on the form where the form changes if the user selects a different RadioButton), the Password field is cleared, even though I...
4
by: volunteer | last post by:
SIMPLE VERSION OF THE QUESTION: XML_TO_COPY.XML <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="xsl_that_tries_to_copy_but_does_not_work.xsl"?> <fruits...
8
by: Steve | last post by:
Hi All I have written some code to rescale my windows forms application forms depending on the users screen resolution The application is designed for 1024 x 768 but some customers have 19"...
4
by: John Kotuby | last post by:
Hi all, I have a simple user-form which accepts contact and profile information for the user to edit and save. All the textboxes are working fine and displaying the expected data, both when the...
10
by: pt36 | last post by:
Hi I have a page with a form and a textbox. before to submit the form I want to chek if the inserted value in the textbox is already present in a database. So I need to pass the textbox value...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.