I have a TextBox on a Web form that I'll be accessing from code. However,
I'd also like execute some Javascript when the control loses focus.
I'm a little confused since the IDE does not seem to present javascript
events when a control has the runat="server" specified. I know I can type it
in but that wouldn't that be specifying my server-side handler rather than
client script?
I'm pretty sure I need this to be a server-side control but would like to
connect some client-side script. Is this even possible?
Thanks.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Re: Question About .NET Controls and Javascript
am 10.01.2008 06:10:41 von Dina
On Jan 10, 9:28 am, "Jonathan Wood" wrote:
> I have a TextBox on a Web form that I'll be accessing from code. However,
> I'd also like execute some Javascript when the control loses focus.
>
> I'm a little confused since the IDE does not seem to present javascript
> events when a control has the runat="server" specified. I know I can type it
> in but that wouldn't that be specifying my server-side handler rather than
> client script?
>
> I'm pretty sure I need this to be a server-side control but would like to
> connect some client-side script. Is this even possible?
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programminghttp://www.softcircuits.com
You 'll have to add a Attributes.Add("onclick", "javascript:function")
on the server side to associate a client event handler to a server
control. {Just check on the syntax coz I've not worked on Web apps 4
sometime.}
Hope it helps.
Regards, Dina
Re: Question About .NET Controls and Javascript
am 10.01.2008 06:49:11 von Moe Sisko
Jonathan,
"Jonathan Wood" wrote in message
news:O7Jf5E0UIHA.5160@TK2MSFTNGP05.phx.gbl...
> I'm pretty sure I need this to be a server-side control but would like to
> connect some client-side script. Is this even possible?
Yes. This should get you going - "Using JavaScript Along with ASP.NET 2.0"
http://msdn2.microsoft.com/en-us/library/aa479390.aspx
HTH,
Moe
Re: Question About .NET Controls and Javascript
am 10.01.2008 08:12:48 von Eliyahu Goldin
Any attribute that is not recognized on server side will just be emitted to
the client as it is. So
will produce
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Jonathan Wood" wrote in message
news:O7Jf5E0UIHA.5160@TK2MSFTNGP05.phx.gbl...
> I have a TextBox on a Web form that I'll be accessing from code. However,
> I'd also like execute some Javascript when the control loses focus.
>
> I'm a little confused since the IDE does not seem to present javascript
> events when a control has the runat="server" specified. I know I can type
it
> in but that wouldn't that be specifying my server-side handler rather than
> client script?
>
> I'm pretty sure I need this to be a server-side control but would like to
> connect some client-side script. Is this even possible?
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"Jonathan Wood" wrote:
> I have a TextBox on a Web form that I'll be accessing from code. However,
> I'd also like execute some Javascript when the control loses focus.
>
> I'm a little confused since the IDE does not seem to present javascript
> events when a control has the runat="server" specified. I know I can type it
> in but that wouldn't that be specifying my server-side handler rather than
> client script?
>
> I'm pretty sure I need this to be a server-side control but would like to
> connect some client-side script. Is this even possible?
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
>
Re: Question About .NET Controls and Javascript
am 10.01.2008 20:02:07 von Jonathan Wood
Yep. Thanks!
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Dina" wrote in message
news:f79ff520-8a63-4a3e-ad33-7cec4191c461@e32g2000prn.google groups.com...
> On Jan 10, 9:28 am, "Jonathan Wood" wrote:
>> I have a TextBox on a Web form that I'll be accessing from code. However,
>> I'd also like execute some Javascript when the control loses focus.
>>
>> I'm a little confused since the IDE does not seem to present javascript
>> events when a control has the runat="server" specified. I know I can type
>> it
>> in but that wouldn't that be specifying my server-side handler rather
>> than
>> client script?
>>
>> I'm pretty sure I need this to be a server-side control but would like to
>> connect some client-side script. Is this even possible?
>>
>> Thanks.
>>
>> --
>> Jonathan Wood
>> SoftCircuits Programminghttp://www.softcircuits.com
>
> You 'll have to add a Attributes.Add("onclick", "javascript:function")
> on the server side to associate a client event handler to a server
> control. {Just check on the syntax coz I've not worked on Web apps 4
> sometime.}
>
> Hope it helps.
> Regards, Dina
Re: Question About .NET Controls and Javascript
am 10.01.2008 20:05:35 von Jonathan Wood
That article looks like just the thing I needed.
However, there's one area that I didn't see it address: How to reference
controls by name. Because if I have a TextBox with ID="txtLbs" it actually
ends up with a name something like
"ctl00_ctl00_ContentPlaceHolder1_MainContent_Wizard1_txtLbs" . I need to
reference two controls from the javascript. I had to hard code these names
because they could potentially change. Anyone have any ideas?
Thanks.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Moe Sisko" wrote in message
news:uJnDIy0UIHA.4868@TK2MSFTNGP03.phx.gbl...
> Jonathan,
>
> "Jonathan Wood" wrote in message
> news:O7Jf5E0UIHA.5160@TK2MSFTNGP05.phx.gbl...
>> I'm pretty sure I need this to be a server-side control but would like to
>> connect some client-side script. Is this even possible?
>
> Yes. This should get you going - "Using JavaScript Along with ASP.NET
> 2.0"
> http://msdn2.microsoft.com/en-us/library/aa479390.aspx
>
> HTH,
> Moe
>
>
Re: Question About .NET Controls and Javascript
am 10.01.2008 20:07:15 von Jonathan Wood
My concern was that it might match one of the ASP.NET control's server-side
events/attributes. But perhaps most of those have different names.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Eliyahu Goldin" wrote in
message news:ewni6e1UIHA.3676@TK2MSFTNGP06.phx.gbl...
> Any attribute that is not recognized on server side will just be emitted
> to
> the client as it is. So
>
> will produce
>
>
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]
> http://msmvps.com/blogs/egoldin
>
>
> "Jonathan Wood" wrote in message
> news:O7Jf5E0UIHA.5160@TK2MSFTNGP05.phx.gbl...
>> I have a TextBox on a Web form that I'll be accessing from code. However,
>> I'd also like execute some Javascript when the control loses focus.
>>
>> I'm a little confused since the IDE does not seem to present javascript
>> events when a control has the runat="server" specified. I know I can type
> it
>> in but that wouldn't that be specifying my server-side handler rather
>> than
>> client script?
>>
>> I'm pretty sure I need this to be a server-side control but would like to
>> connect some client-side script. Is this even possible?
>>
>> Thanks.
>>
>> --
>> Jonathan Wood
>> SoftCircuits Programming
>> http://www.softcircuits.com
>>
>
>
Re: Question About .NET Controls and Javascript
am 10.01.2008 20:09:06 von Jonathan Wood
Heh, I looked at a table of javascript events had didn't relate to onblur
being when a control lost focus. That name only makes sense in an odd sort
of way. Cool.
I also found a good article based on another suggestion. But do you have any
ideas how I would reference other controls from javascript, given that the
IDs of ASP.NET controls can change substantially by the time the HTML is
rendered?
Thanks!
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Peter Bromberg [C# MVP]" wrote in message
news:A85D8A21-C7D9-4704-9D6B-13F17390D527@microsoft.com...
> For lost focus you would do:
>
> myTextBox.Attributes.Add("onblur", "javascript:myfunction")
>
> -- Peter
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> MetaFinder: http://www.blogmetafinder.com
>
>
> "Jonathan Wood" wrote:
>
>> I have a TextBox on a Web form that I'll be accessing from code. However,
>> I'd also like execute some Javascript when the control loses focus.
>>
>> I'm a little confused since the IDE does not seem to present javascript
>> events when a control has the runat="server" specified. I know I can type
>> it
>> in but that wouldn't that be specifying my server-side handler rather
>> than
>> client script?
>>
>> I'm pretty sure I need this to be a server-side control but would like to
>> connect some client-side script. Is this even possible?
>>
>> Thanks.
>>
>> --
>> Jonathan Wood
>> SoftCircuits Programming
>> http://www.softcircuits.com
>>
>>
Re: Question About .NET Controls and Javascript
am 11.01.2008 00:21:30 von Jonathan Wood
Looks like I got this working. I used the ClientID property to obtain the
final control ID.
Thanks!
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Jonathan Wood" wrote in message
news:e2qTMv7UIHA.4092@TK2MSFTNGP06.phx.gbl...
> That article looks like just the thing I needed.
>
> However, there's one area that I didn't see it address: How to reference
> controls by name. Because if I have a TextBox with ID="txtLbs" it actually
> ends up with a name something like
> "ctl00_ctl00_ContentPlaceHolder1_MainContent_Wizard1_txtLbs" . I need to
> reference two controls from the javascript. I had to hard code these names
> because they could potentially change. Anyone have any ideas?
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
> "Moe Sisko" wrote in message
> news:uJnDIy0UIHA.4868@TK2MSFTNGP03.phx.gbl...
>> Jonathan,
>>
>> "Jonathan Wood" wrote in message
>> news:O7Jf5E0UIHA.5160@TK2MSFTNGP05.phx.gbl...
>>> I'm pretty sure I need this to be a server-side control but would like
>>> to connect some client-side script. Is this even possible?
>>
>> Yes. This should get you going - "Using JavaScript Along with ASP.NET
>> 2.0"
>> http://msdn2.microsoft.com/en-us/library/aa479390.aspx
>>
>> HTH,
>> Moe
>>
>>
>