Avatar of kmcbrearty
kmcbrearty
Flag for United States of America asked on

Find Element With JavaScript When UserControl Used Multiple Times

Maybe I am making this more complicated than it is but for the life of me I can not find any information on it.  Basically what I want to do is place a hidden element on a user control and write JavaScript that will read that value.  The problem I have is that it needs to be able to work when there is more than one user control present on the page.

I know that I can not place the JavaScript code on the user control itself because it should only be added to the page once.  I currently have all of my JavaScript in a file and I add it to the page using Page.ClientScript.RegisterClientScriptInclude.  So the question is how do I write JavaScript that can be placed in the file and read the value of a hidden element on the user control that is calling the function and make sure I am reading the right control.

Maybe there is another way to accomplish what I am trying to do so I will try to give this a little more context.  The user control I am creating contains a RadToolBar that has buttons the user will press to perform various actions.  One of the buttons will perform a delete operation so I want to confirm the user really wants to delete it.  My current plan is to use RadWindow to display a confirmation message.  The code that I have found to do this is:

            var btn; 
            function onToolBarClientButtonClicking(sender, args) { 
                var button = args.get_item(); 
 
                if (button.get_commandName() == "DeleteSelected") { 
                    if (document.getElementById('hdn_Hosp').value) { 
                        args.set_cancel(true); 
                        btn = args.get_item(); 
                        confirmFn('Delete ' + document.getElementById('hdn_Hosp').value + '?'); 
                    } 
                } 
            } 
 
            function confirmFn(text) { 
                var callBackFn = function (arg) { 
                    if (arg) { 
                        document.getElementById('hdn_Hosp').value = ""; 
                        btn.click(); 
                    } 
                } 
                radconfirm(text, callBackFn); 
            } 

Open in new window


I think this code could be written so that it doesn't use a hidden element.  My second issue though is that I need to get a translated message to display.  I already have the translations server side so my plan was to put the translated text in a hidden element that could be read and displayed.
JavaScriptASP.NETAJAX

Avatar of undefined
Last Comment
kmcbrearty

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
kmcbrearty

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy