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.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.
>
Also I think non-"runat=server" HTML controls can be read with
Request.Params["ControlID"]
"Sergey Poberezovskiy" <SergeyPoberezovskiy@.discussions.microsoft.com> wrote
in message news:CAEF1D8B-4315-4057-9C87-3A0AA506B553@.microsoft.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.
>>
>>
>
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" <SergeyPoberezovskiy@.discussions.microsoft.com> wrote
> in message news:CAEF1D8B-4315-4057-9C87-3A0AA506B553@.microsoft.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.
> >>
> >>
> >>
>
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" <SergeyPoberezovskiy@.discussions.microsoft.com> wrote
in message news:4D55005A-8A64-4672-81B3-011F8452D7EE@.microsoft.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 Magaa" wrote:
>> Also I think non-"runat=server" HTML controls can be read with
>> Request.Params["ControlID"]
>>
>> "Sergey Poberezovskiy" <SergeyPoberezovskiy@.discussions.microsoft.com>
>> wrote
>> in message news:CAEF1D8B-4315-4057-9C87-3A0AA506B553@.microsoft.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.
>> >>
>> >>
>> >>
>>
>>
>
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" <SergeyPoberezovskiy@.discussions.microsoft.com> wrote
> in message news:4D55005A-8A64-4672-81B3-011F8452D7EE@.microsoft.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" <SergeyPoberezovskiy@.discussions.microsoft.com>
> >> wrote
> >> in message news:CAEF1D8B-4315-4057-9C87-3A0AA506B553@.microsoft.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.
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
0 comments:
Post a Comment