473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

get textbox.ClientID in a usercontrol

Hi,

I've researched this a lot and have a well understanding but still
can't get the darn textbox in the javascript.

I have a textbox that is set to runat="server" and I have a client
function for a comboBox when selectitemindexchanged happens it will
trigger. I know it goes into that because I did a alert("test"). Now
in there I want to take the item in the comboBox and put it in the
textbox that is runat="server". I know I have to use the
textbox.ClientID to get a reference to the textbox because its inside a
usercontrol.

So I am trying to do
var txtBox = document.getElementbyId("<%=textBox.ClientID%>").v alue;
or
var txtBox = document.getElementbyId("<%=txtBoxSnrInsp.ClientID %>");

alert(txtBox.ID)

to verify I have access to the textbox, but it never works. I've seen
many other examples on the net, but I feel I'm doing something wrong or
it isn't working. I know that since its in a usercontrol that the ID
is preappended with the usercontrol name that is why I must use
ClientID. Of course if I delete runat="server" then I can gain access
to the textbox, but I need that because when the user clicks save on
the usercontrol it will take the attributes in the textboxes and update
them to the database. Please anyone have any code example for this
scenario?

Aug 8 '06 #1
9 15338
<da****@sharpesoft.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
I know I have to use the textbox.ClientID to get a reference to the
textbox because its inside a usercontrol.
You don't *have* to do it that way - you just have to know the correct name
of the textbox once it's been sent down to the client machine.
So I am trying to do
var txtBox = document.getElementbyId("<%=textBox.ClientID%>").v alue;
or
var txtBox = document.getElementbyId("<%=txtBoxSnrInsp.ClientID %>");

alert(txtBox.ID)
Neither of these will work, because your textbox is inside a usercontrol.

Easiest way is to do a View Source once the page has been loaded, and see
how the name of the textbox has been constructed. Thereafter, it'll be a
simple matter for you to refer to it in your client-side JavaScript.
Aug 8 '06 #2
Few things,

One this user control is in a multiview. The multiview has several
user controls in it. I can't find the textbox in the source code.
I've read that you can reference a textbox that is in a usercontrol via
ClientID. You are saying there is no way to reference a textbox via
clientID?

David

Aug 8 '06 #3
If this user control is not dynamically loaded then you can reference
the textbox id in javascript as UserControlID_textBoxID.

For example if you give the id for the user control in question as
"MyUserControl"
and textbox id is "MyTextBox".

Then when this textbox renders to the web page.. its id would become
"MyUserControl_MyTextBox"
da****@sharpesoft.com wrote:
Few things,

One this user control is in a multiview. The multiview has several
user controls in it. I can't find the textbox in the source code.
I've read that you can reference a textbox that is in a usercontrol via
ClientID. You are saying there is no way to reference a textbox via
clientID?

David
Aug 8 '06 #4
<da****@sharpesoft.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
One this user control is in a multiview.
Sigh... NOW you tell us that...!
The multiview has several user controls in it. I can't find the textbox
in the source code.
Is the control in question in the "current" MultiView page...? Only the
controls in the current page are actually downloaded to the client, unlike
previous implementations of similar functionality achieved by dynamically
showing / hiding divs, etc...
I've read that you can reference a textbox that is in a usercontrol via
ClientID.
Yes you can, so long as you understand how ASP.NET constructs control IDs
before sending the HTML to the client.
You are saying there is no way to reference a textbox via clientID?
No I'm not - I'm saying that a textbox in a UserControl in a MultiView will
be called something different, probably <ControlID>_<ClientID>...

If your textbox is not actually downloaded (i.e. it's not in the current
multiview page), you'll NEVER be able to reference it client-side...
Aug 8 '06 #5

Mark Rae wrote:
<da****@sharpesoft.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
One this user control is in a multiview.

Sigh... NOW you tell us that...!
The multiview has several user controls in it. I can't find the textbox
in the source code.

Is the control in question in the "current" MultiView page...? Only the
controls in the current page are actually downloaded to the client, unlike
previous implementations of similar functionality achieved by dynamically
showing / hiding divs, etc...
I've read that you can reference a textbox that is in a usercontrol via
ClientID.

Yes you can, so long as you understand how ASP.NET constructs control IDs
before sending the HTML to the client.
You are saying there is no way to reference a textbox via clientID?

No I'm not - I'm saying that a textbox in a UserControl in a MultiView will
be called something different, probably <ControlID>_<ClientID>...

If your textbox is not actually downloaded (i.e. it's not in the current
multiview page), you'll NEVER be able to reference it client-side...
Aug 8 '06 #6
The multiview page index is set by what a user selects on a panel. So
he clicks the panel the usercontrol appears on the screen by setting
the multiview index for that usercontrol. Inside that usercontrol I
have javascript there were I want to reference that textbox that is ran
on the server side. Hope that helps out more. Sorry if there was
confusion on my part.
I'll try the controlID_clientID thing.

David

Aug 8 '06 #7
One more thing. Does the textbox being inside a telerik ajaxpanel also
make a difference as to what level I need to reference this textbox via
client side? So on the usercontrol, I have a telerik ajaxpanel. So
when a few of the controls do postbacks they use ajax. It works well
and nice. Inside that ajax panel is the textbox that I want to
reference clientside, that ajax panel is on the usercontrol, that
usercontrol is in a multiview page, on the main webpage, The main
webpage can change which user control is viewable via a panel, that
will change its index.

Hope that clears it up more.

Aug 8 '06 #8
I was able to solve it. I looked at the Page load event to see inside
there what the textbox.clientID was to get it since it wasn't appearing
in the source code. It was like you said the Usercontrol_textboxid.
But it was appending a 1 to the usercontrol so like
usercontrol1_textboxid. Thanks,

David

Aug 8 '06 #9
Ohh it does.. I thought it was simply the id of the user control placed on
the web form. Check to see if the user control id has "1" as part of the id
<da****@sharpesoft.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
But it was appending a 1 to the usercontrol so like
usercontrol1_textboxid.

Aug 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robbie | last post by:
I have a Web Form with some tailored logos and artwork. The web form also has a user control that has typical registration info on it (Name, Company Name, etc.) One of the fields, a TextBox, is a...
5
by: Mark Friedman | last post by:
Does anyone know how to reference a subcontrol of a UserControl within client-side script. For example, if I have a TextBox as one of the elements of my UserControl with an id of "MyTextBox", how...
3
by: Steven Zilberman | last post by:
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...
6
by: Shimon Sim | last post by:
Is there a consistent way to find out the id of child controls of the UserControl. Should I just use this.name+"_+control.Id;? Shimon
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
3
by: TCORDON | last post by:
How can I make a UserControl run some javascript when it loads? this is so the control sets focus to a textbox it contains. TIA!
0
by: Iain | last post by:
A placeholder a repeater and a couple of textboxes walk into a bar....haha... No, Seriously, I have a placeholder, a repeater, the repeater itemtemplate has a textbox in it, and a submit button...
7
by: Andrus | last post by:
I have UserControls in MDI child forms containing TextBoxes and other controls. When user re-activates form, I need that Control which was last activated is activated again. Currently *first*...
1
by: varunkumarid | last post by:
Hi to All, I want to Compare the Two Textbox ClientId not a Value of them, whether clientid is equal i perform something oterwise not. for (var i = 2; i <=...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.