Showing posts with label masterpage. Show all posts
Showing posts with label masterpage. Show all posts

Wednesday, March 21, 2012

Is it a bug? Using animations in a masterpage doesnt work. Please help.

This is the error I get when I run the page:

Sys.ArgumentException: AjaxControlToolkit.Animation.Animation.set_animationTarget requires the ID of a Sys.UI.DomElement or Sys.UI.Control. No element or control could be found corresponding to "Panel2".

Here is the masterpage:

<%@dotnet.itags.org.MasterLanguage="VB"CodeFile="MasterPage2.master.vb"Inherits="MasterPage2" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headid="Head1"runat="server">

<title>Is it a bug?</title>

</head>

<body>

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<ajaxToolkit:AnimationExtenderID="AnimationExtender1"runat="server"TargetControlID="Panel1">

<Animations>

<OnHoverOver>

<FadeOutDuration=".5"Fps="20"AnimationTarget="Panel2"/>

</OnHoverOver>

<OnHoverOut>

<FadeInDuration=".5"Fps="20"AnimationTarget="Panel2"/>

</OnHoverOut>

</Animations>

</ajaxToolkit:AnimationExtender>

<asp:PanelID="Panel1"runat="server"Height="50px"Width="125px">Text to hover over.</asp:Panel>

<br/>

<br/>

<asp:PanelID="Panel2"runat="server"Height="50px"Width="125px">Text to fade out.</asp:Panel>

<asp:contentplaceholderid="ContentPlaceHolder1"runat="server">

</asp:contentplaceholder>

</form>

</body>

</html>

Here is the small example page:

<%@dotnet.itags.org.PageLanguage="VB"MasterPageFile="~/MasterPage2.master"AutoEventWireup="false"CodeFile="Test7.aspx.vb"Inherits="Test7"title="Untitled Page" %>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

Just some text

</asp:Content>

Here is a page where it works just fine, not using a master page:

<%@dotnet.itags.org.PageLanguage="VB"AutoEventWireup="false"CodeFile="Test8.aspx.vb"Inherits="Test8" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<ajaxToolkit:AnimationExtenderID="AnimationExtender1"runat="server"TargetControlID="Panel1">

<Animations>

<OnHoverOver>

<FadeOutDuration=".5"Fps="20"AnimationTarget="Panel2"/>

</OnHoverOver>

<OnHoverOut>

<FadeInDuration=".5"Fps="20"AnimationTarget="Panel2"/>

</OnHoverOut>

</Animations>

</ajaxToolkit:AnimationExtender>

<asp:PanelID="Panel1"runat="server"Height="50px"Width="125px">

Text to hover over.</asp:Panel>

<br/>

<br/>

<asp:PanelID="Panel2"runat="server"Height="50px"Width="125px">

Text to fade out.

</asp:Panel>

</form>

</body>

</html>

Can you please try to help me to figure out what is wrong with this, please?

Hi ,

In the working and the non-working scenario , go to the view-source of the page and copy the $create Function call and post it here .

Hope this helps


OK, I will gladly post the different results:

Here is the working one:

<script type="text/javascript">
<!--
Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(AjaxControlToolkit.Animation.AnimationBehavior, {"OnHoverOut":"{\"AnimationName\":\"FadeIn\",\"Duration\":\".5\",\"Fps\":\"20\",\"AnimationTarget\":\"Panel2\",\"AnimationChildren\":[]}","OnHoverOver":"{\"AnimationName\":\"FadeOut\",\"Duration\":\".5\",\"Fps\":\"20\",\"AnimationTarget\":\"Panel2\",\"AnimationChildren\":[]}","id":"AnimationExtender1"}, null, null, $get("Panel1"));
});
// -->
</script>

And here is the non working one.

<script type="text/javascript">
<!--
Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(AjaxControlToolkit.Animation.AnimationBehavior, {"OnHoverOut":"{\"AnimationName\":\"FadeIn\",\"Duration\":\".5\",\"Fps\":\"20\",\"AnimationTarget\":\"ctl00_Panel2\",\"AnimationChildren\":[]}","OnHoverOver":"{\"AnimationName\":\"FadeOut\",\"Duration\":\".5\",\"Fps\":\"20\",\"AnimationTarget\":\"Panel2\",\"AnimationChildren\":[]}","id":"ctl00_AnimationExtender1"}, null, null, $get("ctl00_Panel1"));
});
// -->
</script>

Just for reference

My Panel 2 is named: ctl00_Panel2

when using a master page. This is strange I think. But the javascript seems to want Panel2 which can be seen at the end of this javascript.


Hi,

The names of the controls getting changed upon placing them in a master page is expected.

Can you see controls named ctl00_Panel1 and ctl00_Panel2 in the View-Source ?


Sorry for my late reply.

Yes, I can see the ctl00_Panel1 and ctl00_Panel2 in the source code.

However, I can't see Panel2 in the source code, but the Javascript seems to be referring to Panel2 as well as ctl00_Panel2.

Any suggestions?


It's normal to see so. This is the internal behavior of asp.net that its client side id is changed when the control is in a namingContainer.

You may change the AnimationTarget="Panel2"/> toAnimationTarget="ctl00_Panel2"/>


ok , this looks really weird ..

if you see the $create call in the non-working one , the TargetControlIDs are messed up

<script type="text/javascript">
<!--
Sys.Application.initialize();
Sys.Application.add_init(function() {
\",\"AnimationTarget\":\"ctl00_Panel2

blahblahblah

\",\"AnimationChildren\":\",\"AnimationTarget\":\"Panel2\",\"AnimationChildren\":});

</script>
Temporary Workaround for this :

IN the Markup , Change AnimationTarget to be AnimationTargetScript ="GetID();"

<scriptlanguage="javascript">

function GetID() {

var panelID = <%=Panel1.ClientID %>

return panelID;

}

</script>

Hope this helps , lemme know if I missed anything


Raymond Wen - MSFT:

It's normal to see so. This is the internal behavior of asp.net that its client side id is changed when the control is in a namingContainer.

You may change the AnimationTarget="Panel2"/> toAnimationTarget="ctl00_Panel2"/>

Your change worked just fine. Thanks a million!!!Big Smile

I hope that this is fixed in the next version of the control toolkit. I can wish atleast.


Phanatic:

ok , this looks really weird ..

if you see the $create call in the non-working one , the TargetControlIDs are messed up

<script type="text/javascript">
<!--
Sys.Application.initialize();
Sys.Application.add_init(function() {
\",\"AnimationTarget\":\"ctl00_Panel2

blahblahblah

\",\"AnimationChildren\":\",\"AnimationTarget\":\"Panel2\",\"AnimationChildren\":});

</script>
Temporary Workaround for this :

IN the Markup , Change AnimationTarget to be AnimationTargetScript ="GetID();"

<scriptlanguage="javascript">

function GetID() {

var panelID = <%=Panel1.ClientID %>

return panelID;

}

</script>

Hope this helps , lemme know if I missed anything

Hello. When I try this, I get "Sys.ArgumentTypeException: Object of type 'Object' cannot be converted to type 'String'. Parameter name: id"

Thanks for helping me!


Thats right ! When the script ran , it converted the ID to be an actual object .

dunno if I am making senseSmile .

The idea is to avoid one from hard-coding the names of the Target Controls . What if you added another contentPlaceHolder tomorrow ?

Hope this helps


I think Phanatic's code has a bug... try:

function GetId() { return '<%= Panel1.ClientID %>'; }

(note the quotes)


Hi,

Right ! the Code is faulty . It passes the ID without any quotes and hence is interpreted as an object.

But , I think the main thing here is :

If you see the $create Function rendered with a MasterPage in the picture .

The same JSON representation for the animation has the complete ID including the ContentPlace holder's ID "ctl00_Panel2" and also without the ContentPlaceHolder as a container , Panel2.

<script type="text/javascript">
<!--
Sys.Application.initialize();
Sys.Application.add_init(function() {
\",\"AnimationTarget\":\"ctl00_Panel2

blahblahblah

\",\"AnimationChildren\":\",\"AnimationTarget\":\"Panel2\",\"AnimationChildren\":});

</script>

Is it possible to add a ScriptManager and/or UpdatePanel to a MasterPage from a ContentPag

I would on like AJAX on one content page and want to add an UpdatePanel to the MasterPage and wrap a UserControl that is being loaded from the MasterPage in that UpdatePanel all from the ContentPage. Is it possbile to do this? I have some code but it is not working.

protected override void OnPreInit( EventArgs e ) { ScriptManager sm =new ScriptManager(); sm.ID ="ScriptManager1"; Master.Controls.Add( sm ); UpdatePanel panel =new UpdatePanel(); panel.ID ="upMaster"; panel.ContentTemplateContainer.Controls.Add(this.Controls[0] ); AsyncPostBackTrigger trig =new AsyncPostBackTrigger(); trig.ControlID ="btnDelete"; trig.EventName ="Click"; panel.Triggers.Add( trig ); Master.Controls.Add( panel );base.OnPreInit( e ); }

I changed my code and now can get the page to load but now I dont see my usercontrol on the masterpage

protected override void OnPreInit( EventArgs e ) { UpdatePanel panel =new UpdatePanel(); panel.ID ="upMaster"; UserControl uc = (( UserControl )Master.FindControl("CartSummary1" )); panel.ContentTemplateContainer.Controls.Add( uc ); panel. //AsyncPostBackTrigger trig =new AsyncPostBackTrigger();//trig.ControlID = "btnDelete"; //trig.EventName = "Click"; //panel.Triggers.Add( trig ); HtmlForm form1 = ( HtmlForm )Master.FindControl("Form1" ); form1.Controls.Add( panel );//Master.Controls.Add( panel );base.OnPreInit( e ); }

Yes,It is possible.

Do it like this:

MasterPage.master:

<%@. Master Language="C#" %>
<%@. Register src="http://pics.10026.com/?src=UserControlA.ascx" TagName="UserControlA" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:UserControlA ID="uc1" runat="server" />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
<asp:contentplaceholder id="ContentPlaceHolder2" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>

Default.aspx:

<%@. Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToString();
}


protected void Page_PreInit(object sender, EventArgs e)
{
HtmlForm form1 = (HtmlForm)Master.FindControl("form1");
ScriptManager sm = new ScriptManager();
sm.ID = "ScriptManager1";
form1.Controls.AddAt(0, sm);

UpdatePanel panel = new UpdatePanel();
panel.ID = "upMaster";
UserControl uc = ((UserControl)Master.FindControl("uc1"));
panel.ContentTemplateContainer.Controls.Add(uc);
form1.Controls.Add(panel);
}

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<div style="display:none;"><asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button1_Click" /></div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<script type="text/javascript" language="javascript">
function doclick(){
$get('<%= Button2.ClientID%>').click();
}
</script>
<asp:Button ID="Button1" runat="server" Text="Button" UseSubmitBehavior="false" OnClientClick="doclick();return false;" />
</asp:Content>

UserControlA.ascx:

<%@. Control Language="C#" ClassName="UserControlA" %>

<asp:TextBox ID="TextBox1" runat="server">TextBox in UserControlA</asp:TextBox>

Best Regards,