master pages and AJAX controls

M

mike

I'm having a problem getting AJAX working with a master page.

I have created a new website using the AJAXControlToolkit template and
default.aspx as follows.

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:panel ID="Panel1" runat="server" Height="134px"
Width="217px">
This is where the definition goes! It should be invisible
until the LinkButton is hovered on.

</asp:panel>
<br />
<asp:LinkButton ID="LinkButton1"
runat="server">LinkButton</asp:LinkButton><br />
<ajaxToolkit:AnimationExtender ID="AnimationExtender1"
runat="server" TargetControlID="LinkButton1">
<Animations>
<OnHoverOver>
<FadeIn AnimationTarget="Panel1" Duration=".
5" />
</OnHoverOver>
<OnHoverOut>
<FadeOut AnimationTarget="Panel1" Duration=".
5" />
</OnHoverOut>
</Animations>

</ajaxToolkit:AnimationExtender>
</form>
</body>
</html>

This page works correctly, fading in when hovering over the LinkButton
and fading out when moving off.

Then I created a master page (I added nothing to it) and a new WebForm
based on this master page.

Here's the WebForm.

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="ATKTest.aspx.cs" Inherits="ATKTest"
Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:panel ID="Panel1" runat="server" Height="134px"
Width="217px">
This is where the definition goes! It should be
invisible until the LinkButton is hovered on.

</asp:panel>
<br />
<asp:LinkButton ID="LinkButton1" runat="server">AM -
Amplitude</asp:LinkButton><br />
<ajaxToolkit:AnimationExtender ID="AnimationExtender1"
runat="server" TargetControlID="LinkButton1">
<Animations>
<OnHoverOver>
<FadeIn AnimationTarget="Panel1" Duration=".
5" />
</OnHoverOver>
<OnHoverOut>
<FadeOut AnimationTarget="Panel1" Duration=".
5" />
</OnHoverOut>
</Animations>

</ajaxToolkit:AnimationExtender>
</div>
</asp:Content>

this page does not work and generates a Javascript error as follows:
----------
Sys.ArgumentException:
AjaxControlToolKit.Animation.Animation.set_animationTarget requires
the ID
of a Sys.UI.DomElement or a Sys.UI.Control. No element or control
could be
found corresponding to 'Panel1'
Parameter name: id
 
B

bruce barker

you need a form in the master page if you remove it from the page.

-- bruce (sqlwork.com)
 
M

mike

The master page has a form tag in it - it is the exact master page
that is created when you select 'New' from the menu and 'Master Page'
from the dialog.
 
A

AndyW

Sys.ArgumentException:
AjaxControlToolKit.Animation.Animation.set_animationTarget requires
the ID
of a Sys.UI.DomElement or a Sys.UI.Control. No element or control
could be
found corresponding to 'Panel1'
Parameter name: id
-----------

Any help is greatly appreciated!

Mike

Being a newbie on this myself, I had a table in an updatepanel and
was getting the same/similar error (from memory).

I had to do something in the codebehind in the page_load method like:

if (table1 == null) table1 = new Table()

then I had to add it to the form using

form1.Controls.Add(table1).


Not sure quite why I had to do this, but it seemed to fix the problem.
 
M

mike

Being a newbie on this myself, I had a table in an updatepanel and
was getting the same/similar error (from memory).

I had to do something in the codebehind in the page_load method like:

if (table1 == null) table1 = new Table()

then I had to add it to the form using

form1.Controls.Add(table1).

Not sure quite why I had to do this, but it seemed to fix the problem.

The error stems from the fact that MasterPages mangle the ID of
controls - Panel1 becomes ctl00_ContentPlaceHolder1_Panel1 (in my
case).
If I hard code this in, it works fine. Maybe creating the
AnimationExtender at runtime in PageLoad would allow me to set the
AnimationTarget to the correct ID, which I can find by using
FindControl. I'll play with it and see.

Mike
 
R

Registered User

The error stems from the fact that MasterPages mangle the ID of
controls - Panel1 becomes ctl00_ContentPlaceHolder1_Panel1 (in my
case).
If I hard code this in, it works fine. Maybe creating the
AnimationExtender at runtime in PageLoad would allow me to set the
AnimationTarget to the correct ID, which I can find by using
FindControl. I'll play with it and see.
The control's ClientID property will provide the control's decorated
name.The assignment

AnimationExtender.AnimationTarget = Panel1.ClientID;

or something similar should work FB

regards
A.G.
 
A

AndyW

The error stems from the fact that MasterPages mangle the ID of
controls - Panel1 becomes ctl00_ContentPlaceHolder1_Panel1 (in my
case).
If I hard code this in, it works fine. Maybe creating the
AnimationExtender at runtime in PageLoad would allow me to set the
AnimationTarget to the correct ID, which I can find by using
FindControl. I'll play with it and see.

Mike

I think there is a UniqueID property.

So something like Panel1.UniqueId.ToString.

I'd have to check tho.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top