views:

1184

answers:

5

I have asp.net form that contains fields. When I access this window, my javascript functions can access the fields via the DOM with the getElementById() method and when I postpack to the server I am receiving the updates made by the client.

However, when I launch the form as a child window using Telerik's RadWindow control, the javascript can not access the hidden fields on the child form. Instead I get null.

My questions are:

  1. Are hidden fields on a child window not accessible when the window is launched from a parent asp.net form?
  2. Has anyone attempted this with Telerik controls and run into issues?

EDIT Craig pointed out that the id may be different. Two additional questions then:

  1. Can you ensure that the id you assign at the server is actually used?
  2. Is using getElementByName() a better mechanism to access DOM elements?
+1  A: 

It is quite possible that the element's ID is not what you think it is. Check the rendered page and see if the ID is there. I am guessing that the page is given a different ID since it is rendered inside another control.

If that is the case, you can have the form render some script that returns the element ID by accessing the controls client ID.

Craig
Thanks for answer - I'm going to check this out.
David Robbins
+1  A: 

To get the ID of your asp.net control do something like this:

<%= theControl.ClientID %>

getElementByName is not as commonly used as getElementById. The ID attribute is supposed to be unique for each element on the page whereas the name attribute can be duplicated.

TonyB
A: 

I use getElementsByName for checkboxes within the same group.

As for the control's ID, TonyB has the right idea, but make sure you refer to the ClientID property in the PreRender event handler, because if you do it too early in the page life cycle, it will not be available yet).

Kon
A: 

Is it possible the that javascript is trying to get a reference to the hidden field before the RadWindow has loaded it? I believe I've run into this before and had to use setTimeout to get around the problem.

Jeremy Bade
+1  A: 

David, I'm sending you this answer because I saw the same issue in my code, and the only REAL solution I found was that I had to support the "OnClick" function in two places... In my case, I was using PetersDatePackage, but it was on a Telerik RAD Strip.

In my case, the control was on a .ascx page, and the JS code was as follows:

function OnIncidentDateChange(ctrl, dtDate, bErr)
{
    var weekday = new Array(7);
    weekday[0] = "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";

    <%=LabelDayOfWeek.ClientID %>.innerText = weekday[dtDate.getDay()];
}

But, this itself was not enough. I had to add THIS code to my parent page. The page that holds the controls for the Telerik strip.

// Dummy function?
function OnIncidentDateChange()
{
}

Once I did that, it worked...

I'm not certain why, to tell you the truth, and it makes no sense to me, and may just be a issue with the PDP package...

LarryF
Thanks Larry - I appreciate it!
David Robbins