Thursday, February 12, 2009

Set Focus to textbox after updatepanel updates

VB.NET

I have a gridview in a update panel displaying a set of records. When I select a record I want to set focus to a text box. This following script will do that

Set the following cod under the script manager or you will get the sys object not found error

<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
//Use timer so that the script will wait .5 sec before it fires to let page complete rendering the txtDSChartNumber element
setTimeout ( 'setFocus(\'txtDSChartNumber\')', 500 );
}
function setFocus(controlid) {
if (document.getElementById(controlid)){
document.getElementById(controlid).focus();
document.getElementById(controlid).select();
}
}
</script>

0 Comments:

Post a Comment

<< Home