how to grab values from javascript generated items?

E

Eric Layman

HI,

Im on dotnet 1.1

I've generated extra checkboxes, textboxes via client side javascript:

eg:
var inputElement = document.createElement('input');

inputElement.setAttribute('type', 'radio');...

inputElement.setAttribute('id', 'xx');

....



How do i capture these values via server side?



Pls advise.

Thanks
 
D

Designing Solutions WD

I don't believe you can via server side.

What you can do is create these elements serverside. Create a
placeholder on your page where you would like to insert the elements
and use the following code.

protected void addItems() {
TextBox t = new TextBox();
t.id = "myID";
Placeholder.Controls.Add(t);
}

protected void getItems() {
string s = myID.text;
}

Hope this helps.
 
T

Thomas Hansen

HI,

Im on dotnet 1.1

I've generated extra checkboxes, textboxes via client side javascript:

eg:
var inputElement = document.createElement('input');

inputElement.setAttribute('type', 'radio');...

inputElement.setAttribute('id', 'xx');

...

How do i capture these values via server side?

var el = document.createElement('input');
el.type='hidden';
el.value = someValue;
el.id='myEl';
theForm.appendChild(el);
....!
Then you can do (server side) stuff like:
string tmp = Request.Params['myEl'];

But in general terms you really shouldn't DO this...!!

Thomas
 
B

bruce barker

you also need to set the postback name

el.name = 'myEl';



-- bruce (sqlwork.com)

Thomas said:
HI,

Im on dotnet 1.1

I've generated extra checkboxes, textboxes via client side javascript:

eg:
var inputElement = document.createElement('input');

inputElement.setAttribute('type', 'radio');...

inputElement.setAttribute('id', 'xx');

...

How do i capture these values via server side?

var el = document.createElement('input');
el.type='hidden';
el.value = someValue;
el.id='myEl';
theForm.appendChild(el);
...!
Then you can do (server side) stuff like:
string tmp = Request.Params['myEl'];

But in general terms you really shouldn't DO this...!!

Thomas
 
E

Eric Layman

Thomas Hansen said:
HI,

Im on dotnet 1.1

I've generated extra checkboxes, textboxes via client side javascript:

eg:
var inputElement = document.createElement('input');

inputElement.setAttribute('type', 'radio');...

inputElement.setAttribute('id', 'xx');

...

How do i capture these values via server side?

var el = document.createElement('input');
el.type='hidden';
el.value = someValue;
el.id='myEl';
theForm.appendChild(el);
...!
Then you can do (server side) stuff like:
string tmp = Request.Params['myEl'];

But in general terms you really shouldn't DO this...!!

Thomas


----- Original Message -----
From: "Thomas Hansen" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Thursday, March 29, 2007 2:36
Subject: Re: how to grab values from javascript generated items?

HI,

Im on dotnet 1.1

I've generated extra checkboxes, textboxes via client side javascript:

eg:
var inputElement = document.createElement('input');

inputElement.setAttribute('type', 'radio');...

inputElement.setAttribute('id', 'xx');

...

How do i capture these values via server side?

var el = document.createElement('input');
el.type='hidden';
el.value = someValue;
el.id='myEl';
theForm.appendChild(el);
...!
Then you can do (server side) stuff like:
string tmp = Request.Params['myEl'];

But in general terms you really shouldn't DO this...!!

Thomas

Hi Thomas,

Thanks for the reply.

May I know why not? Sometimes they may be instances which we may have to
generate extra table rows or mayb extra textboxes on the fly.

Im curious whether dotnet catered for these situations and perhaps there's a
nice built in widget to do the validations for these on the fly controls! =)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top