Finding a div in an Ajax Accordion

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
3/20/2012 9:25:36 AM
Gravatar
Total Posts 148

Finding a div in an Ajax Accordion

I am writing a custom feature that includes an Ajax Accordion that uses a div inside the <Header> tag of the Accordion.  Is there a way to obtain the id of this div in JavaScript? I'm trying to dynamically write to this div with a custom handler. I need to include the runat="server" attribute in order to initialize the div in my PreRender event. But, doing so mangles the id so I can't find it.  The FindControl won't find div's so I cant use that in my PreRender event.

3/20/2012 10:56:53 AM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Finding a div in an Ajax Accordion

If you search the source code for getElementById, you'll see a lot of places where JavaScript is being built programmatically to access .NET controls, and one of those instances will probably match your scenario. Generally you need to use [control].ClientID to substitute in the appropriate value for JavaScript.

This thread might help you too.

Jamie

3/20/2012 11:43:24 AM
Gravatar
Total Posts 148

Re: Finding a div in an Ajax Accordion

Thank you so much for that link.

I kept trying

document.getElementById('<%=this.FindControl("mydivid").ClientID %>').value;

But it wouldn't work but this did:

document.getElementById('<%=mydivid.ClientID%>').value;


3/20/2012 12:00:53 PM
Gravatar
Total Posts 148

Re: Finding a div in an Ajax Accordion

I forgot to clear the cache.

It was still working from when I hard coded the id generated my .NET I found from the source page.  

The "<%mydiv.ClientID%>" still doesn't work.

3/20/2012 12:14:32 PM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Finding a div in an Ajax Accordion

When you step through with the debugger, what does mydiv.ClientID resolve to? how does that compare to what's shown when you view the source of the rendered page?

3/20/2012 12:40:30 PM
Gravatar
Total Posts 148

Re: Finding a div in an Ajax Accordion

It's working again!!

I need to put the JavaScript on the same page as my control or it won't work!

You cannot reference an external JavaScript file... the Server code won't run.

Thanks again.

3/20/2012 12:56:24 PM
Gravatar
Total Posts 18439

Re: Finding a div in an Ajax Accordion

I think a couple of controls you should study that will give you ideas about how to work with javascript in your own controls and features are:

  • TwitterWidget.cs - a server control that inherits from <asp:Panel and wires itself up to the div that panel renders as using ClientID and it shows how to build up a script using StringBuilder. It has 2 scripts, it shows how to include a main script from twitter and StringBuilder is used to wire up the instance of the widget to the div
  • SkinSetting.ascx.cs a UserControl example it builds some javascript to wireup a preview link for the skins listed in the <asp:DropDownList, see also the SkinSetting.ascx file that has the <asp:DropDownList

Hope that helps,

Joe

3/21/2012 10:25:45 AM
Gravatar
Total Posts 148

Re: Finding a div in an Ajax Accordion

Is there a way to still use an external JavaScript file and have the Server code run? I want to be able to cache the JavaScript code.

3/21/2012 10:36:27 AM
Gravatar
Total Posts 18439

Re: Finding a div in an Ajax Accordion

No, you should design your main javascript so that you pass in the ids for elements, and then use a smaller script rendered in the control to invoke your main script. So your main script can be external but it can't have any dependencies on things in your page or control, you have to pass that stuff in.

like jquery ui widgets are implemented in external files, then you only need a small script in the control to wire up a jquery widget using a selector with ids from your control.

Hope that helps,

Joe

You must sign in to post in the forums. This thread is closed to new posts.