Search code examples
javascriptasp.netdopostbackunique-id

How to get UniqueID from document.getElementById()?


I want to use __doPostBack javascript function.

__doPostBack(obj.UniqueID,'');

But I only know ClientID of my object -

ctl00_cpholder_myObjId 
document.getElementById("ctl00_cpholder_myObjId").id //This will get ctl00_cpholder_myObjId,but UniqueID is ctl00$cpholder$myObjId

How can I get UniqueID for PostBack? Can I simply replace '_' with '$'?
Thank u.


Solution

  • If you have client id and want to get unique id from javascript, you can try

    var uniqueId = document.getElementById("ctl00_cpholder_myObjId").name;
    

    or

    var uniqueId = document.getElementById("ctl00_cpholder_myObjId").getAttribute("name");
    

    name property will return unique id.