4 Replies - 2758 Views - Last Post: 14 December 2012 - 10:28 AM Rate Topic: -----

#1 mvcwannab  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-July 12

Retrieving control using javascript given a control's id

Posted 13 December 2012 - 12:45 PM

I am trying to do this right now using multiple user controls on a page. The user control is a file browser control that was written which contains 5 objects, 2 server asp controls and 3 client inputs. What I'm trying to do is get the main page to locate one of the two server controls within the user control for the input that was clicked on.
...
<asp:TextBox ID="Textbox1" runat="server"/>
<input type="button" id="button1"/>
...


in main page
var someValue = '';

function setValueInUC(someValue){
   var sTxtName = 'txt' + someValue;
   document.getElementById(sTxtName).value = someValue;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Retrieving control using javascript given a control's id

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1062
  • View blog
  • Posts: 4,138
  • Joined: 02-July 08

Re: Retrieving control using javascript given a control's id

Posted 13 December 2012 - 06:48 PM

The first thing I see is your textbox's name is Textbox1 and your looking for txt and someValue.

This post has been edited by _HAWK_: 13 December 2012 - 06:49 PM

Was This Post Helpful? 1
  • +
  • -

#3 mvcwannab  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-July 12

Re: Retrieving control using javascript given a control's id

Posted 14 December 2012 - 07:06 AM

That is a typo in the example. The reason that the code isn't working is because txt + someValue is just the ID of the control and not the ClientID. document.getElementById looks at clientIDs, which are the fully qualified (for lack of a better term at this moment) name, such as pMain_ctl00_etc. Is there a way in javascript to find a control given a controls ID, or a way to get the clientID of a control given the ID?
In the server side code, I could find the control by using the parent's control.findcontrol function, however I'm trying to keep from posting back to the server to accomplish this task.

This post has been edited by mvcwannab: 14 December 2012 - 07:08 AM

Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1062
  • View blog
  • Posts: 4,138
  • Joined: 02-July 08

Re: Retrieving control using javascript given a control's id

Posted 14 December 2012 - 10:24 AM

Maybe:

var someValue = '<%=Object.ClientId %>';

Was This Post Helpful? 0
  • +
  • -

#5 mvcwannab  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 26-July 12

Re: Retrieving control using javascript given a control's id

Posted 14 December 2012 - 10:28 AM

I'm trying to find the object based on the ID that was passed into the function from the UC. For now, I'm working around this by using a rarely used property on an input button to store the clientID of the new object.
I was looking for something simlar to
var someValue = '<%=sTxtName.ClientID%>';


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1