Edit dynamic control by javascript

So you want to change the properties of a control, such as button "btnPost".

Seems rufly easy to accomplish, unless SharePoint, DotNetNuke or other environment decides to change the ID property of the control, adding internal IDs.

Like this:
ctl00_m_g_d14f2004_461a_4c76_9224_70143135d269_btnGen

So how do you change, say, the display option of the control, to make it visible or hidden?

The trick is to make a function that looks for the control, given a regular expression.

btnGen.Attributes.Add("onclick", "this.style.display='none';var re = new RegExp('btnPost', 'g');var elems = document.getElementsByTagName('*'), i = 0, el;while (el = elems[i++]){if (el.id.match(re)){document.getElementById(el.id).style.display='';location.href='" + url + "';}}"); //hide button

I must say, creadits to make this possible go to Kor's postings on webdeveloper.com, where we can find the complete function.

Comments

Popular posts from this blog

Breaking down document locking in SharePoint

Working around X-Frame-Options for iframes

Document ID not being generated