Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting HTML Control Values back to Serverside script

Status
Not open for further replies.

Steve101

Programmer
Mar 29, 2002
1,473
0
0
AU
I am using some client side script to dynamically add rows to a table to simulate a datasheet where the number of rows can vary. This uses the Document Object Model. Inside the table cells, I am adding HTML Text INPUT controls.

Here are my questions:

(a) The existing form that I am using has mostly ASP Text controls, which are processed on Postback when an ASP button is pressed. Is there any way that I can get access to these HTML Control's values from the serverside script on postback? I also need to be able to initialise them from data obtained from a Server database.

(b) I like the ability to grow the HTML table via clientside script. It is just so fast as no roundtrip is required back to the server. However as stated above, I am struggling to figure how to get the data to/from the server into the controls. What are my other options to achieve the same capability.

I hope that this is clear.

TIA,




Steve Lewy
Solutions Developer
SimplyData
simplydata.com.au
(dont cut corners or you'll go round in circles)
 
a) Yes. This is a by-design behavior, with which you should be able to retrieve and set the control values. They're in the form scope, or can be referenced with "Me.whatevercontrol.value".

b) I'm not sure that server-side controls play well with DHTML-manipulated elements. It looks like you'd have to use generic controls and populate them with hand code, or evaluate the POST form fields and manipulate from there. The problem is that server-side controls are encrypted in VIEWSTATE and any client-side element additions don't update VIEWSTATE.

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'll have the roast duck with the mango salsa.
 
Thanks for the reply Phil.

Perhaps I didnt make myself clear.

The control I am attempting to access from the serverside postback script is defined as an HTML control:
ie.
<input type="text" id="HTMLText" value="123" />

This has no visibility to my serverside scripting; i.e. reference to Me.HTMLText.value produces a diagnostic "HTMLText not a member of ..... ". What are my options on serverside to get hold of this value, or is it not possible without the client submitting the form (or perhaps using client side script to move the control's value into an intermediate ASP Text contol using client side script (which I would prefer to avoid).

Cheers,


Steve Lewy
Solutions Developer
SimplyData
simplydata.com.au
(dont cut corners or you'll go round in circles)
 
What about using a server side control like a label, then it won't be an issue. Or use runat="server" in the control definition.
 
Steve,

You can't use Me. to refer to client-side controls.

jbenson001,

He can't use server-side, because the elements are generated dynamically by client-side Javascript, depending on user actions.

This entry has an interesting discussion about the problem, with a couple of suggested workarounds. The key is getting access to the old-fashioned POST header info.







Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'll have the roast duck with the mango salsa.
 
Your first problem, if you just want to get a reference to the actual data, can probably be solved by getting the value though Request.Form. If you do want to actually get a reference to the control, you'll have to add the runat="server" tag like jbenson001 suggested.

Your second problem may be a good scenario as when to use an AJAX method as it should be fairly quick but could be done server side.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks all for your input so far. I may be between a rock and a hard place here, mixing HTML and ASP Controls. Dilema is:

If I do a standard submit of the form, I get access to the standard form fields via Request.Form etc, but I lose the postback capability.

If I use an ASP button to initiate the postback, I lose the ability to see the HTML controls created dynamically by the client.

So, the "chemistry" kind of makes these two approaches mutually exclusive. Am I understanding this correctly? I have sort of assumed that using ASP buttons makes the makes the HTML Submit button redundant, but that was before I tried including some HTML controls and wanted to pass their values back to the backend.

Cheers,



Steve Lewy
Solutions Developer
SimplyData
simplydata.com.au
(dont cut corners or you'll go round in circles)
 
Option 1:

Use Request.Form to read values and dynamically build server-side equivalents to the client-side controls ("<input type='text'.../>" would be an ASP.NET TextBox for example) so when you respond to the request, the inputs don't disappear.

Option 2:

Use AJAX to ineteract with the server, thus never having to worry about leaving the page you built with client script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top