I am getting a javascript error which says that window.document.all(...) is a null or not an object. Thanks. Steven[quote] >-----Original Message----- >Hi, > >I don't believe there is a way to do this with server-[/quote] side[quote] >programming. However, doesn't the JavaScript >window.document.all("textBoxMyTextBox").focus(); work? > >Greetz, >Domien >[quote] >>-----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[/quote][/quote] you.[quote][quote] >>. >>[/quote] >. >[/quote] [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <09a601c34c68$2688dfc0$a501280a@phx.gbl> [ref] => <09d901c34c60$68ca84e0$a401280a@phx.gbl> <08d701c34c65$29f6bdb0$a601280a@phx.gbl> [htmlstate] => on_nl2br [postusername] => Steven [ip] => stevenzilberman [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> -- Best Regards Vidar Petursson ============================== Microsoft Internet Client & Controls MVP ============================== "Steven" wrote in message news:09a601c34c68$2688dfc0$a501280a@phx.gbl...[quote] > For some reason it's not working. My asp code looks like > this: >
> Width="120px"> >
> > The JavaScript code looks like this: > > > I am getting a javascript error which says that > window.document.all(...) is a null or not an object. > > Thanks. > > Steven[quote] > >-----Original Message----- > >Hi, > > > >I don't believe there is a way to do this with server-[/quote] > side[quote] > >programming. However, doesn't the JavaScript > >window.document.all("textBoxMyTextBox").focus(); work? > > > >Greetz, > >Domien > >[quote] > >>-----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[/quote][/quote] > you.[quote][quote] > >>. > >>[/quote] > >. > >[/quote][/quote] [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => <09d901c34c60$68ca84e0$a401280a@phx.gbl> <08d701c34c65$29f6bdb0$a601280a@phx.gbl> <09a601c34c68$2688dfc0$a501280a@phx.gbl> [htmlstate] => on_nl2br [postusername] => Vidar Petursson [ip] => theking@icysoft [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> > > > I am getting a javascript error which says that > window.document.all(...) is a null or not an object.[/quote] Steven, 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 = @" "; if (!this.IsStartupScriptRegistered("SetWebControlFocus")) this.RegisterStartupScript("SetWebControlFocus", string.Format(script, UserName.ClientID)); Hope this helps. Chris. ------------- C.R. Timmons Consulting, Inc. [url]http://www.crtimmonsinc.com/[/url] [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => <09d901c34c60$68ca84e0$a401280a@phx.gbl> <08d701c34c65$29f6bdb0$a601280a@phx.gbl> <09a601c34c68$2688dfc0$a501280a@phx.gbl> [htmlstate] => on_nl2br [postusername] => Chris R. Timmons [ip] => crtimmons@X_NOS [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 4 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> focusing on a textbox - ASP.NET General

focusing on a textbox - ASP.NET General

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....

  1. #1

    Default 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

  2. #2

    Default 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.doent.all("UserName").focus();
    //-->
    </script>

    I am getting a javascript error which says that
    window.doent.all(...) is a null or not an object.

    Thanks.

    Steven
    >-----Original Message-----
    >Hi,
    >
    >I don't believe there is a way to do this with server-
    side
    >programming. However, doesn't the JavaScript
    >window.doent.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
    you.
    >>.
    >>
    >.
    >
    Steven Guest

  3. #3

    Default 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(doent.forms[0].UserName) doent.forms[0].UserName.focus();
    }
    onload = doFocus;
    //-->
    </script>



    --
    Best Regards
    Vidar Petursson
    ==============================
    Microsoft Internet Client & Controls MVP
    ==============================
    "Steven" <stevenzilbermanalum.rpi.edu> wrote in message
    news:09a601c34c68$2688dfc0$a501280aphx.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.doent.all("UserName").focus();
    > //-->
    > </script>
    >
    > I am getting a javascript error which says that
    > window.doent.all(...) is a null or not an object.
    >
    > Thanks.
    >
    > Steven
    > >-----Original Message-----
    > >Hi,
    > >
    > >I don't believe there is a way to do this with server-
    > side
    > >programming. However, doesn't the JavaScript
    > >window.doent.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
    > you.
    > >>.
    > >>
    > >.
    > >

    Vidar Petursson Guest

  4. #4

    Default Re: focusing on a textbox

    "Steven" <stevenzilbermanalum.rpi.edu> wrote in
    news:09a601c34c68$2688dfc0$a501280aphx.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.doent.all("UserName").focus();
    > //-->
    ></script>
    >
    > I am getting a javascript error which says that
    > window.doent.all(...) is a null or not an object.
    Steven,

    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"">
    <!--
    doent.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

Similar Threads

  1. Focusing a TextInput control
    By justria in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: April 11th, 09:06 PM
  2. Activating (focusing) new bookmark?
    By Jeff_Bowell@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 2
    Last Post: December 31st, 09:10 PM
  3. Focusing more on Ruby ... Windows ver?
    By Ron Jeffries in forum Ruby
    Replies: 8
    Last Post: September 27th, 01:10 AM
  4. Focusing...
    By Snowy Rose in forum Photography
    Replies: 2
    Last Post: August 30th, 08:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •