473,568 Members | 2,939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:
RequiredFieldVa lidator_Text1
RegularExpressi onValidator_Tex t1

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 registerstartup script and
registerclients idescript and neither worked. However javascript eval
seems to work:

In the HTML, i have:

<body onload="javascr ipt:window.hist ory.go(1);
eval(document.F orm1.txtJavascr ipt.value);">
<form id="Form1" method="post" runat="server">
<INPUT id="txtJavascri pt" type="hidden" runat="server"
NAME="txtJavasc ript">

then I init the javascript in Page_Load of the codebehind:

if not (IsPostBack) then
' SET FOCUS ON FIRST CONTROL
txtJavascript.V alue = "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_TextChang ed(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles Text1.TextChang ed

'TEST CHANGE CONTENTS OF THE HIDDEN JAVASCRIPT BOX
txtJavascript.V alue = "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)
RequiredFieldVa lidator_Text1.V alidate()
RegularExpressi onValidator_Tex t1.Validate()

' -----------------------------------------------------------------------------
' SET FOCUS DEPENDING ON VALIDATION
If RequiredFieldVa lidator_txtSeco ndaryAmount.IsV alid And
RegularExpressi onValidator_txt SecondaryAmount .IsValid Then
' CALCULATE SOME FIELDS BASED ON NEW Text1 VALUE
Call subRecalculate( Text1.text, Text4.text, Text5.text)
' GOTO NEXT CONTROL
txtJavascript.V alue = "document.Form1 ." & Text2.UniqueID &
".focus();"
Else
' STAY AT SAME CONTROL
txtJavascript.V alue = "document.Form1 ." & Text1.UniqueID &
".focus();"
End If

End Sub ' Text1_TextChang ed
Nov 18 '05 #1
1 1745
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.U niqueID & ".focus();"
Text1.Attribute s.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.Attribute s.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="javas cript:document. Form1.Text2.foc us();__doPostBa ck('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
5715
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 of 'email1' to RED to bring this to my attention. This needs to change on a 'per record' basis, so as I scroll through the records using the...
7
9313
by: Daniel Jung | last post by:
Hi ======== Problem: ======== I want images in table rows connect vertically. All images are 32 px in height. =====
17
2531
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 with a link to old information that suggests use of "navigator": http://developer.irt.org/script/43.htm
1
2358
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 in advance This is the code that loops through all rows. find the textboxes controls Private Sub btnguardarplandesarrollo_Click(ByVal sender As...
2
2699
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 have EnableViewState set to True. None of the other TextBoxes lose their value. I also tried using Session variables to store the value between...
4
1394
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 date="20060621"> <fruit name="orange" /> </fruits> COPY_RESULT_THAT_IS_INTENDED.XML orange
8
8436
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" screens and want to use 1280 x 1024 etc I am using vb.net 2005 Code sample..............................................................
4
4887
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 screen is first displayed and after a save of changed data. The text boxes are being populated during the Page_Load event. However, when I change...
10
21514
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 by a javascript link to another page to check. my code is <a href="javascript:location.href='page_check.php' "Go check </a> and this work and open...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.