Results 1 to 11 of 11

Thread: [RESOLVED] [2005] How to select all text in a gridview textbox ?

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Resolved [RESOLVED] [2005] How to select all text in a gridview textbox ?

    I'm using following code try to achieve my work but it doesn't work.



    ASP Code:
    1. Dim descTB As TextBox
    2.                 Dim strScript As String
    3.                 descTB = .Rows(.EditIndex).Cells(2).FindControl("txtdesc")
    4.                 descTB.Focus()
    5.  
    6. strScript = "<script language=""JavaScript"">" & vbCrLf & _
    7.                              vbTab & descTB.ID & ".Select();" & _
    8.                              vbCrLf & "<" & "/script>"
    9.                 Page.ClientScript.RegisterStartupScript(GetType(String), "HighLightText", strScript)

    What is my problem ?
    Can anyone help me to figure out.

    Thanks
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2005] How to select all text in a gridview textbox ?

    Hey,

    I forget exactly how this works, but am I not right in saying that even though the ID of the TextBox is TextBox1, when it gets rendered to the page, it is something like GridView1_Ctrl01_TextBox1, this is to ensure that since the TextBox is repeated multiple times in the GridView that the ID remains unique.

    You can verify this in the source of the page by manually looking for the textbox.

    In which case, I think you should be using the ClientID in the above, not the ID:

    http://msdn.microsoft.com/en-us/libr....clientid.aspx

    Hope that helps!!

    Gary

  3. #3

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: [2005] How to select all text in a gridview textbox ?

    Really appreciate your help,

    I had tried the solution you were provided to me.

    the output of strScript is
    javascript Code:
    1. "<script language="JavaScript">
    2.     ctl00_ContentPlaceHolder1_MasterT_grdStatusMaster_ctl02_txtDesc.Select();
    3. </script>"

    It doesn't work
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2005] How to select all text in a gridview textbox ?

    Hey,

    Did you verify that there is actually a control called that it actually rendered? You can check that just by looking at the view source of the page.

    Also, my javascript isn't great, so this could be completely off, but I think I am right in saying that javascript doesn't have a .Select, but rather a .Focus.

    Give that a try and see how you get on.

    Gary

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] How to select all text in a gridview textbox ?

    1.
    "<script language="JavaScript">
    2.
    ctl00_ContentPlaceHolder1_MasterT_grdStatusMaster_ctl02_txtDesc.Select();
    3.
    </script>"
    That's wrong, it should be



    Code:
          "<script language="JavaScript">
       
              document.getElementById('ctl00_ContentPlaceHolder1_MasterT_grdStatusMaster_ctl02_txtDesc').Select();
       
          </script>"
    You'll have to change your generated javascript to include the document.getElementById() bit. You may also have to call .focus() first, before .select().

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2005] How to select all text in a gridview textbox ?

    Oops, good point, never spotted that

  7. #7

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: [2005] How to select all text in a gridview textbox ?

    Thanks all of you,

    I have did the amendment based on the advice from mendnak and gep13.
    The code as below.
    asp Code:
    1. Dim strScript As String
    2.                 descTB = .Rows(.EditIndex).Cells(2).FindControl("txtdesc")
    3.                 'descTB.Focus()
    4.  
    5.                 strScript = "<script language=""JavaScript"">" & vbCrLf & _
    6.                              vbTab & "document.getElementById('" & descTB.ClientID & "')" & ".focus();" & _
    7.                               vbCrLf & vbTab & "document.getElementById('" & descTB.ClientID & "')" & ".Select();" & _
    8.                              vbCrLf & "<" & "/script>"
    9.                 Page.ClientScript.RegisterStartupScript(GetType(String), "HighLightText", strScript)


    The textbox focus is work fine but it will not select all text inside the textbox.

    So still cannot work.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2005] How to select all text in a gridview textbox ?

    Hey,

    I believe I am correct in saying that:

    Code:
    .Select()
    should be:

    Code:
    .select()
    Remember, javascript is case sensitive. Depending on what browser you are using, remember to enable all javascript errors, as this time of things would show up in the error console.

    Hope that helps!!

    Gary

  9. #9

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: [2005] How to select all text in a gridview textbox ?

    Thanks Mendnak and gep13.

    I realized that javascript is case sensitive. A upper case "S" wasted my 2 days. LoL.......
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] [2005] How to select all text in a gridview textbox ?

    Doesn't VS 2005 have javascript intellisense?

  11. #11
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] [2005] How to select all text in a gridview textbox ?

    It does to an extent, but it is far better in 2008.

    And in this case the JavaScript is being created as a RegisterStartupScript, so you wouldn't get intellisense at that point.

Posting Permissions

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



Click Here to Expand Forum to Full Width