|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to Address Other Controls' IDs?I've created a User Defined Control (.cs class) using JavaScript to address another control. This only works when my UDC resides on the .aspx page itself. If I add it to a Web User Control (.ascx), the target control's ID attribute gets changed by ASP.NET and I can't address it anymore from my generated JavaScript code. Can someone please enlighten me on the following: How can I get the prefix of the container my UDC is in? Is there a function available telling me if the target ID belongs to a server control (Runat="server")? Here's some more information: My UDC basically provides a property allowing the web page author to enter the ID of the targeted control, like: <myNS:myCtrl Runat="server" ID="myControl" TargetID="MoveIt"/> ... <asp:Panel Runat="server" ID="MoveIt"></asp:Panel> In the source of my UDC I generate JavaScript to address the other control: Page.RegisterClientScriptBlock("x" , "<script>document.getElementById(" + TargetID + ")...</script>"); If TargetID points to a server control, I'd like to be able to add the context prefix of my UDC's container to the generated JavaScript code. TIA, Axel Dahmen Your javascript in the client can't have a hardcoded ID for the control.
Instead you're going to have to dynamically alter & emit your javascript to take into consideration whatever that ID will be. The way you determine the ID in the browser is to ask the control on the server via the control's ClientID property. -Brock DevelopMentor http://staff.develop.com/ballen Show quoteHide quote > Hi, > > I've created a User Defined Control (.cs class) using JavaScript to > address another control. This only works when my UDC resides on the > .aspx page itself. If I add it to a Web User Control (.ascx), the > target control's ID attribute gets changed by ASP.NET and I can't > address it anymore from my generated JavaScript code. > > Can someone please enlighten me on the following: How can I get the > prefix of the container my UDC is in? Is there a function available > telling me if the target ID belongs to a server control > (Runat="server")? > > Here's some more information: > > My UDC basically provides a property allowing the web page author to > enter the ID of the targeted control, like: > > <myNS:myCtrl Runat="server" ID="myControl" TargetID="MoveIt"/> > ... > <asp:Panel Runat="server" ID="MoveIt"></asp:Panel> > In the source of my UDC I generate JavaScript to address the other > control: > > Page.RegisterClientScriptBlock("x" > , "<script>document.getElementById(" + TargetID + > ")...</script>"); > If TargetID points to a server control, I'd like to be able to add the > context prefix of my UDC's container to the generated JavaScript code. > > TIA, > Axel Dahmen Actually this is what I did. See the C# excerpt below. It's from my UDC's
Page_Init() function. -------- Show quoteHide quote "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message news:b8743b114ee7e8c7bcaa52522485@msnews.microsoft.com... > Your javascript in the client can't have a hardcoded ID for the control. > Instead you're going to have to dynamically alter & emit your javascript > to take into consideration whatever that ID will be. The way you determine > the ID in the browser is to ask the control on the server via the control's > ClientID property. > > -Brock > DevelopMentor > http://staff.develop.com/ballen > > > Hi, > > > > I've created a User Defined Control (.cs class) using JavaScript to > > address another control. This only works when my UDC resides on the > > .aspx page itself. If I add it to a Web User Control (.ascx), the > > target control's ID attribute gets changed by ASP.NET and I can't > > address it anymore from my generated JavaScript code. > > > > Can someone please enlighten me on the following: How can I get the > > prefix of the container my UDC is in? Is there a function available > > telling me if the target ID belongs to a server control > > (Runat="server")? > > > > Here's some more information: > > > > My UDC basically provides a property allowing the web page author to > > enter the ID of the targeted control, like: > > > > <myNS:myCtrl Runat="server" ID="myControl" TargetID="MoveIt"/> > > ... > > <asp:Panel Runat="server" ID="MoveIt"></asp:Panel> > > In the source of my UDC I generate JavaScript to address the other > > control: > > > > Page.RegisterClientScriptBlock("x" > > , "<script>document.getElementById(" + TargetID + > > ")...</script>"); > > If TargetID points to a server control, I'd like to be able to add the > > context prefix of my UDC's container to the generated JavaScript code. > > > > TIA, > > Axel Dahmen > > I simply think you need to do:
Page.RegisterClientScriptBlock("x" , "<script>document.getElementById('" + myControl.ClientID + '")...</script>"); Note the additional single quotes added to getElementById -Brock DevelopMentor http://staff.develop.com/ballen Show quoteHide quote > Actually this is what I did. See the C# excerpt below. It's from my > UDC's Page_Init() function. > > -------- > "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message > news:b8743b114ee7e8c7bcaa52522485@msnews.microsoft.com... >> Your javascript in the client can't have a hardcoded ID for the >> control. Instead you're going to have to dynamically alter & emit >> your javascript to take into consideration whatever that ID will be. >> The way you determine the ID in the browser is to ask the control on >> the server via the >> > control's > >> ClientID property. >> >> -Brock >> DevelopMentor >> http://staff.develop.com/ballen >>> Hi, >>> >>> I've created a User Defined Control (.cs class) using JavaScript to >>> address another control. This only works when my UDC resides on the >>> .aspx page itself. If I add it to a Web User Control (.ascx), the >>> target control's ID attribute gets changed by ASP.NET and I can't >>> address it anymore from my generated JavaScript code. >>> >>> Can someone please enlighten me on the following: How can I get the >>> prefix of the container my UDC is in? Is there a function available >>> telling me if the target ID belongs to a server control >>> (Runat="server")? >>> >>> Here's some more information: >>> >>> My UDC basically provides a property allowing the web page author to >>> enter the ID of the targeted control, like: >>> >>> <myNS:myCtrl Runat="server" ID="myControl" TargetID="MoveIt"/> >>> ... >>> <asp:Panel Runat="server" ID="MoveIt"></asp:Panel> >>> In the source of my UDC I generate JavaScript to address the other >>> control: >>> Page.RegisterClientScriptBlock("x" >>> , "<script>document.getElementById(" + TargetID + >>> ")...</script>"); >>> If TargetID points to a server control, I'd like to be able to add >>> the >>> context prefix of my UDC's container to the generated JavaScript >>> code. >>> TIA, >>> Axel Dahmen Thanks Allen, still I've found the solution meanwhile:
ctrl.NamingContainer+"_"ctrl.ClientID does the job to qualify a control's id for javaScript. Axel ------------ Show quoteHide quote "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message news:b8743b114f3208c7bcb5368611a7@msnews.microsoft.com... > I simply think you need to do: > > Page.RegisterClientScriptBlock("x" > , "<script>document.getElementById('" + myControl.ClientID + > '")...</script>"); > > Note the additional single quotes added to getElementById > > -Brock > DevelopMentor > http://staff.develop.com/ballen > > > Actually this is what I did. See the C# excerpt below. It's from my > > UDC's Page_Init() function. > > > > -------- > > "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message > > news:b8743b114ee7e8c7bcaa52522485@msnews.microsoft.com... > >> Your javascript in the client can't have a hardcoded ID for the > >> control. Instead you're going to have to dynamically alter & emit > >> your javascript to take into consideration whatever that ID will be. > >> The way you determine the ID in the browser is to ask the control on > >> the server via the > >> > > control's > > > >> ClientID property. > >> > >> -Brock > >> DevelopMentor > >> http://staff.develop.com/ballen > >>> Hi, > >>> > >>> I've created a User Defined Control (.cs class) using JavaScript to > >>> address another control. This only works when my UDC resides on the > >>> .aspx page itself. If I add it to a Web User Control (.ascx), the > >>> target control's ID attribute gets changed by ASP.NET and I can't > >>> address it anymore from my generated JavaScript code. > >>> > >>> Can someone please enlighten me on the following: How can I get the > >>> prefix of the container my UDC is in? Is there a function available > >>> telling me if the target ID belongs to a server control > >>> (Runat="server")? > >>> > >>> Here's some more information: > >>> > >>> My UDC basically provides a property allowing the web page author to > >>> enter the ID of the targeted control, like: > >>> > >>> <myNS:myCtrl Runat="server" ID="myControl" TargetID="MoveIt"/> > >>> ... > >>> <asp:Panel Runat="server" ID="MoveIt"></asp:Panel> > >>> In the source of my UDC I generate JavaScript to address the other > >>> control: > >>> Page.RegisterClientScriptBlock("x" > >>> , "<script>document.getElementById(" + TargetID + > >>> ")...</script>"); > >>> If TargetID points to a server control, I'd like to be able to add > >>> the > >>> context prefix of my UDC's container to the generated JavaScript > >>> code. > >>> TIA, > >>> Axel Dahmen > >
Custom dropdownlist that displays a listbox
Simple question ??? Using DataList - table and headers How to build dynamicaly a menu in ASP.Net 2.0 (VS 2005) ? DataItem in DataListItem is null. Output the HTML contents of a dynamically created control Picture on a button DHTML MENU problem in IE Anybody using Table control? How Do I Use a CheckBox to Update a Bit Type Data Field in a DataGrid |
|||||||||||||||||||||||