Read Page Control Values from Javascript User Control

G

Guest

How do I read the value of an html input control from inside a javascript
user control?

An aspx page contains a user control that attempts to read a value from an
html input control in the aspx page.

For example:

In the aspx page, the control is defined as:
<input id="txtTMOStart" runat="server" name="txtTMOStart" type="TEXT"
size="30" value="test" enableviewstate="true" />

The Javascript user control attempts to read the value from the control:
var controlValue = document.aspnetForm.txtTMOStart.value;

However, controlValue is always null even thought the control is initialized
with a value.

Note:
If the runat="server" attribute is removed from the html control, the value
returned is not null, however, I can't read the control’s value from the code
behind file!

Any ideas?

Thanks.
 
G

Guest

Yes...same result. Thanks for your response.

Eliyahu Goldin said:
Did you try document.getElementById("txtTMOStart" )?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Roy said:
How do I read the value of an html input control from inside a javascript
user control?

An aspx page contains a user control that attempts to read a value from an
html input control in the aspx page.

For example:

In the aspx page, the control is defined as:
<input id="txtTMOStart" runat="server" name="txtTMOStart" type="TEXT"
size="30" value="test" enableviewstate="true" />

The Javascript user control attempts to read the value from the control:
var controlValue = document.aspnetForm.txtTMOStart.value;

However, controlValue is always null even thought the control is initialized
with a value.

Note:
If the runat="server" attribute is removed from the html control, the value
returned is not null, however, I can't read the control's value from the code
behind file!

Any ideas?

Thanks.
 
E

Eliyahu Goldin

Is the input control inside the user control?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Roy said:
Yes...same result. Thanks for your response.

Eliyahu Goldin said:
Did you try document.getElementById("txtTMOStart" )?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Roy said:
How do I read the value of an html input control from inside a
javascript
user control?

An aspx page contains a user control that attempts to read a value from
an
html input control in the aspx page.

For example:

In the aspx page, the control is defined as:
<input id="txtTMOStart" runat="server" name="txtTMOStart" type="TEXT"
size="30" value="test" enableviewstate="true" />

The Javascript user control attempts to read the value from the
control:
var controlValue = document.aspnetForm.txtTMOStart.value;

However, controlValue is always null even thought the control is initialized
with a value.

Note:
If the runat="server" attribute is removed from the html control, the value
returned is not null, however, I can't read the control's value from
the code
behind file!

Any ideas?

Thanks.
 
E

Eliyahu Goldin

Check the html source of the page when is it rendered in your browser. You
should be able to see the real id of the control.
 
G

Guest

I have no problem reading the id of the control. The problem I’m having is
retrieving the *value* the control contains. Yet, if I remove the attribute
“runat=’server’†from the declaration of the control, the value is not null
and I can retrieve it.
 
E

Eliyahu Goldin

Can you check how does the html for the input control look like when you
have runat=server?
 
G

Guest

As I wrote in the my initial post and if I understand your statement, the
html for the html input control looks like:

<input id="txtTMOStart" runat="server" name="txtTMOStart" type="TEXT"
size="30" value="test" enableviewstate="true" />
 
E

Eliyahu Goldin

No, I mean the real html that is produced by asp.net and arrives to your
browser. It doesn't have neither runat nor enableviewstate attributes since
those are server ones. Your javascript is dealing with this real html and I
suspect the html for the control in topic may look differently from what you
think.

To see the real html, get the page on your browser screen, right-click the
mouse and select "View Source" option. This is how it's called in IE, other
browsers may have different names for the same thing. The html for the page
will open in an editor window. Search for "txtTMOStart" and see what element
is that.
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top