Well, I haven't found a way to do it using ONLY the Attributes.Add() method
yet (if there is one, it might be unavoidable depending on how they coded
the Add() method), but I think I figured out a workaround that I think will
work for all situations. Rather than doing:
Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"
TextBox2.Attributes.Add("onKeyPress", jscode)
I will do the following:
Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"
Page.RegisterClientScriptBlock("TextBox2_RestrictInput", "<script
type=""text/javascript"">function TextBox2_RestrictInput(){" & jscode &
"}</script>")
TextBox2.Attributes.Add("onKeyPress", "return TextBox2_RestrictInput();")
This basically writes my JavaScript code as a function, and then I just
return the value returned by the function. Apparently
RegisterClientScriptBlock leaves the &'s alone, so it works. Maybe this is
how ASP.NET intended all generated JavaScript to be added, although I think
it would be nice to be able to do it without the RegisterClientScriptBlock
method, but I guess I'll have to deal with it this way for now.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/ [quoted text, click to view] "Sean" <Sean@discussions.microsoft.com> wrote in message
news:CAD51A64-8552-4636-963E-A04AE776BA3A@microsoft.com...
> Ah..I see, yeah I have no idea either. Its clear that you have a clear
> understanding what I was getting at and also how it doesnt apply to your
> situation.
>
> sorry about that.
>
> "Nathan Sokalski" wrote:
>
>> I don't think that either of those are part of the solution, because they
>> refer to the stuff between the opening and closing tags, like the
>> following:
>>
>> <HTMLTAG>innertext or innerhtml</HTMLTAG>
>>
>> My goal is to add an attribute to the tag, which would be like the
>> following:
>>
>> <HTMLTAG ATTRIBUTE="ATTRIBUTEVALUE"></HTMLTAG>
>>
>> Using the Attributes.Add() method that I showed in my initial posting
>> adds
>> the attribute to the right place, but it replaces the ATTRIBUTEVALUE's
>> &'s
>> with &'s, therefore causing the JavaScript to have incorrect syntax.
>> --
>> Nathan Sokalski
>> njsokalski@hotmail.com
>>
http://www.nathansokalski.com/ >>
>> "Sean" <Sean@discussions.microsoft.com> wrote in message
>> news:A50D83E1-C52E-4532-8EDB-B3530888D5DC@microsoft.com...
>> > Abstractly speaking .innerHTML or .innerText might solve the problem
>> > (?)
>> >
>> > I just don't know specifically where you can and/or want to try
>> > .innerText
>> > or .innerHTML.
>> >
>> > More of a general answer sorry I wish I had more time to look at it.
>> >
>> >
>> >
>> > "Nathan Sokalski" wrote:
>> >
>> >> I add a JavaScript event handler to some of my Webcontrols using the
>> >> Attributes.Add() method as follows:
>> >>
>> >>
>> >> Dim jscode as String = "return
>> >> (event.keyCode>=65&&event.keyCode<=90);"
>> >> TextBox2.Attributes.Add("onKeyPress", jscode)
>> >>
>> >>
>> >> You will notice that jscode contains the JavaScript Logical And
>> >> operator
>> >> (&&). However, ASP.NET renders this as && in the code that is
>> >> output, even though it is intended to be client-side JavaScript, not a
>> >> visible onscreen character. How can I get ASP.NET to output
>> >>
>> >>
>> >> onKeyPress="return (event.keyCode>=65&&event.keyCode<=90);"
>> >>
>> >> instead of
>> >>
>> >> onKeyPress="return (event.keyCode>=65&&event.keyCode<=90);"
>> >>
>> >>
>> >> I am using VB.NET to write my server-side code, and am using Visual
>> >> Studio
>> >> ..NET 2003 with .NET 1.1. Thanks in advance for any help you can give.
>> >> --
>> >> Nathan Sokalski
>> >> njsokalski@hotmail.com
>> >>
http://www.nathansokalski.com/ >> >>
>> >>
>> >>
>>
>>
>>