Link to home
Start Free TrialLog in
Avatar of SamCash
SamCashFlag for United States of America

asked on

document.getElementById(sender.xxxx)

Expert,

I am worried about line 7 (MARKED:     // THE FOLLOWING LINE IS WORRYSOME...)  as I found this parameter in the debugger.  This works (at least on Chrome) but I could not find any documentation using  "sender._element.id" .  Whenever I did stuff that was not documented, it came back to haunt me.  

What is the proper or best practice to get the "element id" from "sender"?

Kind Regards
Sam

js code:
//
//<ajaxtoolkit:TabPanel ID="tpTabPanel" ... <do not runat=server>
//              OnClientClick="setIframeSrc" data-iframeId="the-id-of-the-iframe" data-srcUrl="Site/webform.aspx">
//
function setIframeSrc(sender, args) {

    // THE FOLLOWING LINE IS WORRYSOME...
    var iframeId = document.getElementById(sender._element.id).getAttribute('data-iframeId'); 

    var oiframe = document.getElementById(iframeId);
    var srcUrl = document.getElementById(sender._element.id).getAttribute('data-srcUrl');
    
    //if (iframeId.IsLoaded == undefined) It is the first time, so load Iframe which will initialize the IsLoaded parameter so it dosen't happen again
    if (oiframe.IsLoaded == undefined) {
        oiframe.src = srcUrl;
        oiframe.IsLoaded = 'true'; //create and set custom attribute
        //alert("oiframe.IsLoaded set -->" + oiframe.IsLoaded + "<--");
    }
    else {
        //alert("oiframe.IsLoaded is defined "); //do nothing...
    }
}

Open in new window

Avatar of HainKurt
HainKurt
Flag of Canada image

why not just use

var iframeId = document.getElementById(sender._element.id).getAttribute('data-iframeId');
var srcUrl = document.getElementById(sender._element.id).getAttribute('data-srcUrl');

>>>

var iframeId = sender._element.getAttribute('data-iframeId'); 
var srcUrl = sender._element.getAttribute('data-srcUrl');

Open in new window



looks same to me... by the way who wrote this? your developers?
where and how frequently you use this?
Avatar of SamCash

ASKER

HainKurt,

Sorry I was out of town until today.

I wrote this code.  As you can tell I am new.  Thank you for the simplification.  I works and I am sure it will be much faster.  It is used every time a tab is clicked.

I am still woried about using  "_element" as I am not able to find any documentation.  Will this work on Exploer, Edge, Firefox, Safari?  Do you have a link to and documentation.

Regards
Sam
I am still woried about using  "_element" as I am not able to find any documentation

I am guessing this is a part of telerik components... are you using Telerik?
If yes, check their documentation, online or offline... it should be on their web site + in the product you have...
Avatar of SamCash

ASKER

HainKurt,

Thanks again for your Expert assistance.

I am not using Telerik or any other.  I am using from the top; HTML, CSS, JavaScript (no JQuery), Ajax, Asp.net, c# and msSQL.  I am using webforms (not MVC) and no other frameworks or 3rd party add-ons.

I found "sender._element.otherproperties" in the chrome debugger.  I tried "sender._element.id" and it worked. SEE ATTACHED SCREEN SHOT.  I have highlighted the tree on the right panel.

I looked for a couple of hours trying to find any documentation on these underscored properties, found none.  This bothers me as I have used undocumented things in the past and at some time in the future things stopped working.  I have seen the underscore used for local/internal variables so I am guessing developers may change their usage/design internally/local as long as the documented public/external ones stay the same, to maintain backwards compatibility, hmmm?

The objective is to simply "get the senders id".  The higher objective was to pass parameters to a function.  I learned one cannot do it from the system event calls so I added parameters to the calling object and then have the called function access those paramerets through "function(sender args)".  But I need the senders id to get the added parameters.

Please help me to properly get the id or point me to the documentation so I can use the Best Practice?

Kind Regards
Sam
i dont see attachement

is sender._element.id same as sender.id?
maybe this is just same as

var iframeId = sender.getAttribute('data-iframeId');

Open in new window


if you create a demo or show me link, I can look at it to see what is sender and what are the properties of it...
Avatar of SamCash

ASKER

HainKurt,

I will try to attach file again.  I will be out for a couple of hours.

I will try
var iframeId = sender.getAttribute('data-iframeId');

Open in new window


Regards
Sam
Capture2017_1011_0822.PNG
from screenshot, it should be

var iframeId = sender._element.getAttribute('data-iframeId'); 

Open in new window

Avatar of SamCash

ASKER

HainKurt,

And thanks again.

Yes, I saw that too and "var iframeId = sender._element.getAttribute('data-iframeId');" is where I got my first solution, however I am still conscerned that "_element" may not be available sometime in the future.  

Your prior comment "var iframeId = sender.getAttribute('data-iframeId');" looks like the correct way , there is no underscores, it is simple.  I think the Best Practice solution will look something like that.  However it returns "Uncaught TypeError: sender.getAttribute is not a function"

I will build a sample solution so you may see the whole thing.

Best Regards
Sam
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial