Mixing server and client controls

S

Shawn Repphan

I have a webform with about 20 html textboxes and checkboxes. I am using
ICallbackEventHandler to page through these successfully. But I need to be
able to accept changes from these fields. How can I access an html field
from ASP.net? Or better yet, how do I access server controls from
javascript? The latter would be possible if ASP.net always gives the
textboxes the excat same ID.
 
G

Guest

If you add runat="server" attribute to your html fields, then you can access
them in you code behind as normal server controls.

To access server control from the javascript, you could write something
similar to the following in your aspx page:

<script language="javascript">
<!--
....
var myJavaScriptControl = document.getElementById('<%=
myServerControl.ClientID %>');
....
// -->
</script>

HTH
 
G

Gabriel Magaña

Also I think non-"runat=server" HTML controls can be read with
Request.Params["ControlID"]
 
G

Guest

I would say Request.Forms["ControlID'] will be more precise, but it would not
allow you to set them upon initial page load, change any of their properties,
etc.


Gabriel Magaña said:
Also I think non-"runat=server" HTML controls can be read with
Request.Params["ControlID"]

Sergey Poberezovskiy said:
If you add runat="server" attribute to your html fields, then you can
access
them in you code behind as normal server controls.

To access server control from the javascript, you could write something
similar to the following in your aspx page:

<script language="javascript">
<!--
...
var myJavaScriptControl = document.getElementById('<%=
myServerControl.ClientID %>');
...
// -->
</script>

HTH
 
S

Shawn Repphan

I decided to just assume that ASP.NET will never change the names of it's
controls. Seems to work so far...
Example:
txtTextBox1 is the ASP.NET name, I can access this textbox from javascript
by using this ID: ctl00_ContentPlaceHolder2_txtTextBox1. The
ContentPlaceHolder2 is there because I am using master pages.
Does anyone see anything wrong with this?

Sergey Poberezovskiy said:
I would say Request.Forms["ControlID'] will be more precise, but it would
not
allow you to set them upon initial page load, change any of their
properties,
etc.


Gabriel Magaña said:
Also I think non-"runat=server" HTML controls can be read with
Request.Params["ControlID"]

"Sergey Poberezovskiy" <[email protected]>
wrote
in message news:[email protected]...
If you add runat="server" attribute to your html fields, then you can
access
them in you code behind as normal server controls.

To access server control from the javascript, you could write something
similar to the following in your aspx page:

<script language="javascript">
<!--
...
var myJavaScriptControl = document.getElementById('<%=
myServerControl.ClientID %>');
...
// -->
</script>

HTH
:

I have a webform with about 20 html textboxes and checkboxes. I am
using
ICallbackEventHandler to page through these successfully. But I need
to
be
able to accept changes from these fields. How can I access an html
field
from ASP.net? Or better yet, how do I access server controls from
javascript? The latter would be possible if ASP.net always gives the
textboxes the excat same ID.
 
G

Guest

It is always safer to use control.ClientID especially if you use them inside
WebControls - this way even if you move your control onto a different
container, you will not have to change the code.

Shawn Repphan said:
I decided to just assume that ASP.NET will never change the names of it's
controls. Seems to work so far...
Example:
txtTextBox1 is the ASP.NET name, I can access this textbox from javascript
by using this ID: ctl00_ContentPlaceHolder2_txtTextBox1. The
ContentPlaceHolder2 is there because I am using master pages.
Does anyone see anything wrong with this?

Sergey Poberezovskiy said:
I would say Request.Forms["ControlID'] will be more precise, but it would
not
allow you to set them upon initial page load, change any of their
properties,
etc.


Gabriel Magaña said:
Also I think non-"runat=server" HTML controls can be read with
Request.Params["ControlID"]

"Sergey Poberezovskiy" <[email protected]>
wrote
in message If you add runat="server" attribute to your html fields, then you can
access
them in you code behind as normal server controls.

To access server control from the javascript, you could write something
similar to the following in your aspx page:

<script language="javascript">
<!--
...
var myJavaScriptControl = document.getElementById('<%=
myServerControl.ClientID %>');
...
// -->
</script>

HTH
:

I have a webform with about 20 html textboxes and checkboxes. I am
using
ICallbackEventHandler to page through these successfully. But I need
to
be
able to accept changes from these fields. How can I access an html
field
from ASP.net? Or better yet, how do I access server controls from
javascript? The latter would be possible if ASP.net always gives the
textboxes the excat same ID.
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top