473,396 Members | 1,703 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,396 software developers and data experts.

Getting viewstate value from readonly textbox in .NET2 (VB)

Hey guys...

I have a form that asks for several dates. I tried using asp calendar
controls to set values of the date textboxes which were readonly. I found
this annoying since each time I advanced a month and/or selected any date,
it posted back and refreshed the page. So, instead, I resorted to an old
javascript function I use a lot. The javascript creates a pop up (html)
window and sets the value of the textbox when the user picks a date. I had
done this many times in ASP.NET1. However, since upgrading to .NET2, I
noticed I was getting errors and the data I was trying to pull and save into
a db from the textboxes was coming up as null.

I did a little research and found out that this was a change made in .NET2.
Readonly textboxes can ONLY get their values from Viewstate or serverside
code, NOT client side like javascripts.

http://forums.asp.net/thread/1134316.aspx

The only way I can get my page to work is to set readonly to false (bad
idea). The above thread suggests that I use a PreRender sub for the
textbox(es). The suggestion is from a guy as MS. However, I added this sub
to my vb code behind file and nothing happened. The textbox is still wide
open.

Protected Sub txtStartDate_PreRender(ByVal Sender As Object, ByVal E As
System.EventArgs)

txtStartDate.Attributes("readonly") = "readonly"

End Sub

Any suggestions or advice? I really would like to use my javascript
calendar pop up functions to set the value of the textbox AND I'd like to
keep the txtboxes to readonly (duh). Any advice?

TIA!

-Shane


Apr 12 '06 #1
9 2702
Sounds like a terrible MS idea. I wonder what their reasoning was?

Anyway, I would try to add a javascript event. try either an onfocus,
that just moves the focus to the calendar. Or an onkeypress that
ignores any keys.

Please let me know how well it works.

Michael Lang
XQuiSoft LLC
http://www.xquisoft.com/

Apr 12 '06 #2
So essentially redirect the focus off the textbox fields so they can never
stay in it long enough to type?

"Mike" <mi**********@xquisoft.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
Sounds like a terrible MS idea. I wonder what their reasoning was?

Anyway, I would try to add a javascript event. try either an onfocus,
that just moves the focus to the calendar. Or an onkeypress that
ignores any keys.

Please let me know how well it works.

Michael Lang
XQuiSoft LLC
http://www.xquisoft.com/

Apr 12 '06 #3
I found out why it was done. I take back my "terrible idea" comment.
It was to prevent security hacks. A read-only field typically should
not be changed by the user, and thus should not be needed on postback.
Of coarse, your property is not REALLY read-only from a business
perspective, you just want them to use the date-picker. Following are
some workarounds.

"Four Guys" say to use the disabled attribute, and use ASP.NET 2.0's
SubmitDisabledControls property to enable them just before postback.
They don't like the enabled attribute since it isn't on all controls.
http://aspnet.4guysfromrolla.com/articles/012506-1.aspx

"Scott" says you shouldn't read readonly fields and instead reread them
from the database. Good for some data like id's, but not good for your
date picker solution. I recommend others reading this post do not use
the other workarounds that Rick is using for id fields used on
postback. That defeats the purpose of the security fix.
http://scottonwriting.net/sowblog/posts/4965.aspx

"Rick" says to get the read-only value from a field using the request:
this.TextBox1.Text = Request[this.TextBox1.UniqueID];
west-wind.com/weblog/posts/3939.aspx
site was down for me. If it is at the time you read this, see the
google cached version:
http://72.14.203.104/search?q=cache:...s&ct=clnk&cd=1

Michael Lang
XQuiSoft LLC
http://www.xquisoft.com/

Apr 12 '06 #4
yes. and another, maybe better javascript route...

onfocus="this.onblur();"

as suggested by Keith Patton in Rick Strahl's blog.
http://west-wind.com/weblog/posts/3939.aspx

http://blog.keithpatton.com/

Overall, I recommend trying the route in my other post where I
mentioned the 4Guys from Rolla approach.

Michael Lang
XQuiSoft LLC
http://www.xquisoft.com/

Apr 12 '06 #5
Oops, major typo. I meant to say the 4Guys "don't like the readonly
attribute since it isn't on all controls.". The disabled attribute is
on all controls.

Apr 12 '06 #6
Thanks for your research. I'll look into it shortly and post my results
back to this thread.

Thanks!
"Mike" <mi**********@xquisoft.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
I found out why it was done. I take back my "terrible idea" comment.
It was to prevent security hacks. A read-only field typically should
not be changed by the user, and thus should not be needed on postback.
Of coarse, your property is not REALLY read-only from a business
perspective, you just want them to use the date-picker. Following are
some workarounds.

"Four Guys" say to use the disabled attribute, and use ASP.NET 2.0's
SubmitDisabledControls property to enable them just before postback.
They don't like the enabled attribute since it isn't on all controls.
http://aspnet.4guysfromrolla.com/articles/012506-1.aspx

"Scott" says you shouldn't read readonly fields and instead reread them
from the database. Good for some data like id's, but not good for your
date picker solution. I recommend others reading this post do not use
the other workarounds that Rick is using for id fields used on
postback. That defeats the purpose of the security fix.
http://scottonwriting.net/sowblog/posts/4965.aspx

"Rick" says to get the read-only value from a field using the request:
this.TextBox1.Text = Request[this.TextBox1.UniqueID];
west-wind.com/weblog/posts/3939.aspx
site was down for me. If it is at the time you read this, see the
google cached version:
http://72.14.203.104/search?q=cache:...s&ct=clnk&cd=1

Michael Lang
XQuiSoft LLC
http://www.xquisoft.com/

Apr 12 '06 #7
a better approach is to have client script set the readonly attribute
instead of the server. this handles the case where client script is
disabled. the user will still be enter the values, even though the
javascript calendar will not work.

i dislike the disable approach, as client script must enable them before
postback and this causes a flicker. also if the postback is slow, the users
can change values and post again.

-- bruce (sqlwork.com)
"Mike" <mi**********@xquisoft.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
Oops, major typo. I meant to say the 4Guys "don't like the readonly
attribute since it isn't on all controls.". The disabled attribute is
on all controls.

Apr 12 '06 #8
OK...after doing much reading (and confusion), I just decided to leave the
fields wide open. My datepicker served two purposes. 1- For convenience.
2 - Making sure the date was valid date. I'll just have to an additional
server-side edit to make sure the dates are legit. I'm still a little
disappointed in this change...but I guess it's better for security issues.

: /


"ShaneFowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:OT**************@TK2MSFTNGP02.phx.gbl...
Thanks for your research. I'll look into it shortly and post my results
back to this thread.

Thanks!
"Mike" <mi**********@xquisoft.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
I found out why it was done. I take back my "terrible idea" comment.
It was to prevent security hacks. A read-only field typically should
not be changed by the user, and thus should not be needed on postback.
Of coarse, your property is not REALLY read-only from a business
perspective, you just want them to use the date-picker. Following are
some workarounds.

"Four Guys" say to use the disabled attribute, and use ASP.NET 2.0's
SubmitDisabledControls property to enable them just before postback.
They don't like the enabled attribute since it isn't on all controls.
http://aspnet.4guysfromrolla.com/articles/012506-1.aspx

"Scott" says you shouldn't read readonly fields and instead reread them
from the database. Good for some data like id's, but not good for your
date picker solution. I recommend others reading this post do not use
the other workarounds that Rick is using for id fields used on
postback. That defeats the purpose of the security fix.
http://scottonwriting.net/sowblog/posts/4965.aspx

"Rick" says to get the read-only value from a field using the request:
this.TextBox1.Text = Request[this.TextBox1.UniqueID];
west-wind.com/weblog/posts/3939.aspx
site was down for me. If it is at the time you read this, see the
google cached version:
http://72.14.203.104/search?q=cache:...s&ct=clnk&cd=1

Michael Lang
XQuiSoft LLC
http://www.xquisoft.com/


Apr 12 '06 #9
Last post! =)

On second thought, I'll just use a CompareValidator to ensure the valid
date.
"ShaneFowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:OZ**************@TK2MSFTNGP02.phx.gbl...
OK...after doing much reading (and confusion), I just decided to leave the
fields wide open. My datepicker served two purposes. 1- For convenience.
2 - Making sure the date was valid date. I'll just have to an additional
server-side edit to make sure the dates are legit. I'm still a little
disappointed in this change...but I guess it's better for security issues.

: /


"ShaneFowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:OT**************@TK2MSFTNGP02.phx.gbl...
Thanks for your research. I'll look into it shortly and post my results
back to this thread.

Thanks!
"Mike" <mi**********@xquisoft.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
I found out why it was done. I take back my "terrible idea" comment.
It was to prevent security hacks. A read-only field typically should
not be changed by the user, and thus should not be needed on postback.
Of coarse, your property is not REALLY read-only from a business
perspective, you just want them to use the date-picker. Following are
some workarounds.

"Four Guys" say to use the disabled attribute, and use ASP.NET 2.0's
SubmitDisabledControls property to enable them just before postback.
They don't like the enabled attribute since it isn't on all controls.
http://aspnet.4guysfromrolla.com/articles/012506-1.aspx

"Scott" says you shouldn't read readonly fields and instead reread them
from the database. Good for some data like id's, but not good for your
date picker solution. I recommend others reading this post do not use
the other workarounds that Rick is using for id fields used on
postback. That defeats the purpose of the security fix.
http://scottonwriting.net/sowblog/posts/4965.aspx

"Rick" says to get the read-only value from a field using the request:
this.TextBox1.Text = Request[this.TextBox1.UniqueID];
west-wind.com/weblog/posts/3939.aspx
site was down for me. If it is at the time you read this, see the
google cached version:
http://72.14.203.104/search?q=cache:...s&ct=clnk&cd=1

Michael Lang
XQuiSoft LLC
http://www.xquisoft.com/



Apr 12 '06 #10

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

Similar topics

9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
1
by: 234 | last post by:
I'm playing around with page inheritence and I'm to the point now where I want to create a form object on a derived page. Here's a truncated version of my 'base' page from which all/most pages in...
5
by: Adrian Parker | last post by:
Trying to write a page with several controls on it, some of which, depending on the process login, are enabled and some disabled. When I click on a save button to cause a postback event to fire,...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
0
by: Groove | last post by:
I've noticed something that's come up twice today alone. In ASP.NET 1, I could reference and use a control's property if the control was set to readonly or if it was set to visible = false. Such...
5
by: Just Me | last post by:
I have a simple page and was trying to test viewstate for a textbox. in my page_load event If not ispostback then textbox1.text="hello" end if
1
by: affi | last post by:
Hi all, I m new to javascript and web development for that matter, so, my questions may sound dumb...........but i will really apperciate any solution ASAP as i m facing a deadline............ ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.