OnFocus event missing from ASP.Net 2.0?

You'd think it'd be simple to do something like this..

<asp:RadioButton ID="rbOne" runat="server" Text="Button One" GroupName="grpOne">       </asp:RadioButton>
<asp:TextBox ID="txtOne" runat="server" OnFocus="rbOne.Checked = true"></asp:TextBox>

But VS2005 is giving me all manner of grief saying the "OnFocus" attribute doesn't exist with textbox...or dropdownlist, or any of those other goodies!


This worked fine when I was using classic ASP!  When a user selects the item from a dropdownlist, or types in a textbox, the corresponding radio button becomes checked...then on submit, see which radio button was selected and perform the appropriate action.

Not sure if there is a way to get the same functionality doing things differently, but any alternative options would be appreciated **grin**

Oh...not sure if you have to do anything in the code behind...with Classic ASP it was all done in Javascript, client-side...but if code behind is necessary, I am more familiar with C# than VB.Net...but can try muddle my way through a translation.

Thanks in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
It should work fine. You'll get a warning from the compiler because IntelliSense won't recognise it as being an attribute of the server control. But it is valid for client-side javascript.
ShaymusBane2Author Commented:
I'm getting a javascript error

"document.frmMain.rbOne is null or not an object"

I'm using .master pages, and I have my frmMain located there...

When I do a view source, the ID of txtOne is altered beyond recognition too...ctrl1_id_txtOne or some such...
Carl TawnSystems and Integration DeveloperCommented:
If you add the OnFocus event via the code-behind then you can factor in the ClientID of the control. Something like:

    txtOne.Attributes.Add("onfocus", rbOne.ClientID + ".checked=true;");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ShaymusBane2Author Commented:
Nice!  That's what I was lookin' for **grin**

SLIGHT variation used...

txtOne.Attributes["OnFocus"] = rbOne.ClientID + ".Checked=true;";

Works perfectly though...AND it's consistent, regardless what page I'm on, or what the form name is...

Thanks for the prompt and complete response.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.