|
-
Mar 8th, 2009, 11:25 PM
#1
Thread Starter
Hyperactive Member
[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:
Dim descTB As TextBox
Dim strScript As String
descTB = .Rows(.EditIndex).Cells(2).FindControl("txtdesc")
descTB.Focus()
strScript = "<script language=""JavaScript"">" & vbCrLf & _
vbTab & descTB.ID & ".Select();" & _
vbCrLf & "<" & "/script>"
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.
-
Mar 9th, 2009, 02:27 AM
#2
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
-
Mar 10th, 2009, 12:21 AM
#3
Thread Starter
Hyperactive Member
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:
"<script language="JavaScript">
ctl00_ContentPlaceHolder1_MasterT_grdStatusMaster_ctl02_txtDesc.Select();
</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.
-
Mar 10th, 2009, 02:41 AM
#4
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
-
Mar 10th, 2009, 03:09 AM
#5
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().
-
Mar 10th, 2009, 03:12 AM
#6
Re: [2005] How to select all text in a gridview textbox ?
Oops, good point, never spotted that
-
Mar 10th, 2009, 08:00 PM
#7
Thread Starter
Hyperactive Member
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:
Dim strScript As String
descTB = .Rows(.EditIndex).Cells(2).FindControl("txtdesc")
'descTB.Focus()
strScript = "<script language=""JavaScript"">" & vbCrLf & _
vbTab & "document.getElementById('" & descTB.ClientID & "')" & ".focus();" & _
vbCrLf & vbTab & "document.getElementById('" & descTB.ClientID & "')" & ".Select();" & _
vbCrLf & "<" & "/script>"
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.
-
Mar 11th, 2009, 02:37 AM
#8
Re: [2005] How to select all text in a gridview textbox ?
Hey,
I believe I am correct in saying that:
should be:
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
-
Mar 11th, 2009, 07:34 PM
#9
Thread Starter
Hyperactive Member
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.
-
Mar 12th, 2009, 05:20 AM
#10
Re: [RESOLVED] [2005] How to select all text in a gridview textbox ?
Doesn't VS 2005 have javascript intellisense?
-
Mar 12th, 2009, 05:28 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|