Ask a Question related to ASP.NET General, Design and Development.
-
Steven Zilberman #1
focusing on a textbox
Is there a way to focus on a textbox in ASP.Net?
Can I do something like textBoxMyTextBox.Focus() ???
Meaning, I can't do it with the JavaScript way, because
JavaScript does not know the form name, and for some
reason it does not see the id of the textbox. Thank you.
Steven Zilberman Guest
-
Focusing a TextInput control
Solved this issue: Had to use callLater(), to focus the component during the next event loop. Stefan http://www.justRIA.com/ -
Activating (focusing) new bookmark?
I just downloaded the Acrobat 8 SDK (now free yea!) and am writing my first Windows plug-in to enhance Acrobat 8's bookmarking capability. I can... -
Focusing more on Ruby ... Windows ver?
OK, after this C# book is over, I'll be getting back into Ruby more. It's more fun in a number of ways. Martin Fowler, who got me using XSLT, has... -
Focusing...
Hi, Quick question. With a manual focus camera, would it be better to focus with or with out one's glasses. I've got an older slr, and I've... -
Canon A1 Focusing Screens
G'day Everyone, I recently acquired a Canon A1 SLR, which goes along well with my AE1 and AV1. My question is, does anybody know if Canon... -
Steven #2
focusing on a textbox
For some reason it's not working. My asp code looks like
this:
<form runat="server">
<asp:TextBox id="UserName" runat="server" MaxLength="10"
Width="120px"></asp:TextBox>
</form>
The JavaScript code looks like this:
<script language="JavaScript">
<!--
window.document.all("UserName").focus();
//-->
</script>
I am getting a javascript error which says that
window.document.all(...) is a null or not an object.
Thanks.
Stevenside>-----Original Message-----
>Hi,
>
>I don't believe there is a way to do this with server-you.>programming. However, doesn't the JavaScript
>window.document.all("textBoxMyTextBox").focus() ; work?
>
>Greetz,
>Domien
>>>-----Original Message-----
>>Is there a way to focus on a textbox in ASP.Net?
>>Can I do something like textBoxMyTextBox.Focus() ???
>>Meaning, I can't do it with the JavaScript way, because
>>JavaScript does not know the form name, and for some
>>reason it does not see the id of the textbox. Thank>.>>.
>>
>Steven Guest
-
Vidar Petursson #3
Re: focusing on a textbox
Hi
Probably the element is not ready/loaded on the client when you call
focus....
Try changing the script to this... should be easy to modify to focus on any
element...
<script language="JavaScript">
<!--
function doFocus(){
if(document.forms[0].UserName) document.forms[0].UserName.focus();
}
onload = doFocus;
//-->
</script>
--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
"Steven" <stevenzilberman@alum.rpi.edu> wrote in message
news:09a601c34c68$2688dfc0$a501280a@phx.gbl...> For some reason it's not working. My asp code looks like
> this:
> <form runat="server">
> <asp:TextBox id="UserName" runat="server" MaxLength="10"
> Width="120px"></asp:TextBox>
> </form>
>
> The JavaScript code looks like this:
> <script language="JavaScript">
> <!--
> window.document.all("UserName").focus();
> //-->
> </script>
>
> I am getting a javascript error which says that
> window.document.all(...) is a null or not an object.
>
> Thanks.
>
> Steven> side> >-----Original Message-----
> >Hi,
> >
> >I don't believe there is a way to do this with server-> you.> >programming. However, doesn't the JavaScript
> >window.document.all("textBoxMyTextBox").focus() ; work?
> >
> >Greetz,
> >Domien
> >> >>-----Original Message-----
> >>Is there a way to focus on a textbox in ASP.Net?
> >>Can I do something like textBoxMyTextBox.Focus() ???
> >>Meaning, I can't do it with the JavaScript way, because
> >>JavaScript does not know the form name, and for some
> >>reason it does not see the id of the textbox. Thank> >.> >>.
> >>
> >
Vidar Petursson Guest
-
Chris R. Timmons #4
Re: focusing on a textbox
"Steven" <stevenzilberman@alum.rpi.edu> wrote in
news:09a601c34c68$2688dfc0$a501280a@phx.gbl:
Steven,> For some reason it's not working. My asp code looks like
> this:
><form runat="server">
><asp:TextBox id="UserName" runat="server" MaxLength="10"
> Width="120px"></asp:TextBox>
></form>
>
> The JavaScript code looks like this:
><script language="JavaScript">
><!--
> window.document.all("UserName").focus();
> //-->
></script>
>
> I am getting a javascript error which says that
> window.document.all(...) is a null or not an object.
Look at the browser's HTML source for your page. I'll bet ASP.NET
modified the control name to something like _ctl0_UserName. ASP.NET
usually does this to controls in a UserControl (.ascx), so there
won't be a name collision if multiple instances of the same
UserControl are on the same page.
The way to fix this is to insert the JavaScript using server-side
code, and use the control's ClientId property to refer to the control
in the JavaScript code.
For example, you can put code like this in the Page_Load event of
your form (C#) to make the UserName TextBox control get focus:
string script = @"
<script language=""javascript"">
<!--
document.getElementById('{0}').focus();
//-->
</script>
";
if (!this.IsStartupScriptRegistered("SetWebControlFoc us"))
this.RegisterStartupScript("SetWebControlFocus",
string.Format(script, UserName.ClientID));
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc.
[url]http://www.crtimmonsinc.com/[/url]
Chris R. Timmons Guest



Reply With Quote

