how to grab values from javascript generated items?

  • Thread starter Thread starter Eric Layman
  • Start date Start date
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
 
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.
 
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
 
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
 
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! =)
 
Back
Top