473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Mixing server and client controls

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.
Jan 18 '06 #1
5 1508
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
"Shawn Repphan" wrote:
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.

Jan 19 '06 #2
Also I think non-"runat=server" HTML controls can be read with
Request.Params["ControlID"]

"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com> wrote
in message news:CA**********************************@microsof t.com...
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
"Shawn Repphan" wrote:
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.

Jan 19 '06 #3
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" wrote:
Also I think non-"runat=server" HTML controls can be read with
Request.Params["ControlID"]

"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com> wrote
in message news:CA**********************************@microsof t.com...
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
"Shawn Repphan" wrote:
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.


Jan 19 '06 #4
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" <Se*****************@discussions.microsoft.com> wrote
in message news:4D**********************************@microsof t.com...
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" wrote:
Also I think non-"runat=server" HTML controls can be read with
Request.Params["ControlID"]

"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com>
wrote
in message news:CA**********************************@microsof t.com...
> 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
> "Shawn Repphan" wrote:
>
>> 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.
>>
>>
>>


Jan 19 '06 #5
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" wrote:
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" <Se*****************@discussions.microsoft.com> wrote
in message news:4D**********************************@microsof t.com...
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" wrote:
Also I think non-"runat=server" HTML controls can be read with
Request.Params["ControlID"]

"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com>
wrote
in message news:CA**********************************@microsof t.com...
> 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
> "Shawn Repphan" wrote:
>
>> 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.
>>
>>
>>


Jan 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
1
by: Matthew Louden | last post by:
Personally, I am totally confused with the following control terms and usage and advantages of each one in ASP.NET web application. Here's what I know so far.. 1. HTML Client Control: understood...
1
by: Lloyd Sheen | last post by:
I am having big time problems seperating the two mention in subject line. I want to create a list of items (listbox or select) from a button click (on the server). The button click will ensure...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
5
by: Mong | last post by:
Hi, I have a webform with various asp controls on it such as textboxes and dropdownlists. I'm fairly new to asp.net coming from VB6 and am wondering when it's best to use client side events and...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
22
by: Mr Newbie | last post by:
I was thinking about developing a workflow application yesterday and was musing over the different approaches than one could take in restricting specific actions on a ticket( Form ) at any said...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
10
by: Ben | last post by:
Hi, I made an application in classic asp (reservation of books and video stuffs for students) and want to migrate to asp.net. The user has to chose a date, then pushung on a submit button. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.