Thursday, March 29, 2012

Server Side Set Focux

I've been researching on how to set focus to a WebControl, and the only results I'm coming across are using JavaScript. I was curious if there was a way to code this on the serverside codebehind (I am using VB) file.
The reason I ask is because I have two DropDownLists, when one is changed, the second is populated from a database based off of what the first one's value is. In the OnSelectedIndexChange event I have set up already, it would be really easy to put at the bottom of this method a DropDownList.setFocus(), but I don't seem to find that method available to the DropDownLists.
Is this is a feature that hasn't been implemented yet, or is there not a way to do this currently in the code behind and only with JavaScript?

DSimmonRemember that your web form is generating HTML and sometimes javascript to the browser to tell it what to show. HTML doesn't have a focus concept. So you are left with javascript. It is easy to set focus by writing code on the server side that generates the precise javascript.

Page.RegisterStartupScript("focus", "<script language='javascript'>document.all['" + DropDownList1.ClientID + "'].setFocus();</script>)
Here is a good solutionview post 821121

regards

0 comments:

Post a Comment