script focus example

  • Thread starter Thread starter selen
  • Start date Start date
S

selen

I am using script for Focus to txtAdi which is textbox in c# web
application.But it doesnt work.

Have you any idea why it doesnt work.What must I do ? can you give me
example.
Because I am beginner in c# asp.net

thanks.......



char c=(char)34;

string script =

"<script language=" + c + "javascript" + c

+ ">" +

" var control = document.getElementById(" + c +

txtAdi + c + ");" +

" if( control != null ){control.focus();}" +

"</script>";

Page.RegisterStartupScript("Focus", script);
 
Adding this somewhere in the html page (I put it after </form>) should set
focus to a control named txtAdi

<script language=javascript>
document.forms[0].item("txtAdi",0).focus();
</script>
 
Btw, there is no reason to add char c = (char)34;
You can use \"

string script = "<script language=\"javascript\">" +
" var control = document.getElementById(\"txtAdi\");" +
" </script>";
 
Back
Top