Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > AJAX UpdatePanel does not refresh after calling Update()-Method

Reply
Thread Tools

AJAX UpdatePanel does not refresh after calling Update()-Method

 
 
Michael Schöller
Guest
Posts: n/a
 
      11-20-2009
Hi,

I'm new to AJAX and has a little Problem to get an UpdatePanel inside an
CustomServerControl to work.
My goal is to create an CustomServerControl with an (at designtime)
unknown number of UpdatePanels, that can be updated seperatly.
Since I'm stuck I create a litte more static testproject to analyse the
problem but I ran out of ideas what I could been missing.
I would be realy glad if someone can show me hwo to get the UpdatePanels
working.

I created an ServerControl-Project called ServerControlTest and an ASP
WebApplication called AXAJTest
The Default.asxp looks like:
--------------------------
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="AJAXTest._Default" %>

<%@ Register assembly="ServerControlTest" namespace="ServerControlTest"
tagprefix="cc1" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000"
ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="Label1" runat="server"
Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>

</div>
<cc1:ServerControl1 ID="ServerControl11" runat="server" />
</form>
</body>
</html>
---------------------
Code Behind looks like:
------------------------------------------------------
using System;

namespace AJAXTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
ServerControl11.Text1 = DateTime.Now.ToString();
ServerControl11.Text2 = DateTime.Now.AddDays(1D).ToString();
}
}

protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
ServerControl11.Text1 = DateTime.Now.ToString();
ServerControl11.Text2 = DateTime.Now.AddDays(1D).ToString();

ServerControl11.TestPanel1.Update();
}
}
}
-----------------------------------------------
The class ServerControl1 in ServerControlTest looks like this:
----------------------------------------------------------
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ServerControlTest
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]
public class ServerControl1 : WebControl
{
private UpdatePanel _testPanel1;
private UpdatePanel _testPanel2;

public UpdatePanel TestPanel1 { get { return _testPanel1; } }
public UpdatePanel TestPanel2 { get { return _testPanel2; } }

[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text1
{
get
{
String s = (String)ViewState["Text1"];
return (s ?? string.Empty);
}

set
{
ViewState["Text1"] = value;
}
}

[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text2
{
get
{
String s = (String)ViewState["Text1"];
return (s ?? string.Empty);
}

set
{
ViewState["Text2"] = value;
}
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
_testPanel1 = new UpdatePanel
{
ID = this.ID + this.IdSeparator + "UpdatePanel1",
UpdateMode = UpdatePanelUpdateMode.Conditional,
ChildrenAsTriggers = false,
Page = this.Page
};
_testPanel2 = new UpdatePanel
{
ID = this.ID + this.IdSeparator + "UpdatePanel2",
UpdateMode = UpdatePanelUpdateMode.Conditional,
ChildrenAsTriggers = false,
Page = this.Page
};
}

protected override void RenderContents(HtmlTextWriter output)
{
Label label1 = new Label {ID = this.ID + this.IdSeparator +
"Label1", Text = Text1};
Label label2 = new Label {ID = this.ID + this.IdSeparator +
"Label2", Text = Text2};
_testPanel1.ContentTemplateContainer.Controls.Add( label1);
_testPanel2.ContentTemplateContainer.Controls.Add( label2);
_testPanel1.RenderControl(output);
_testPanel2.RenderControl(output);
}
}
}
---------------------------------------------------

Regards
Michael
 
Reply With Quote
 
 
 
 
Michael Schöller
Guest
Posts: n/a
 
      11-23-2009
Hi,

I found a solution myself.
There are 3 things that must be changed.
1) The UpdatePanels has to be declares in the PageLoad-Event and added
to the Controls-Container.
2) The Label-Controls has to be declared in the PageLoad-Event and added
to the updatePanel
3) The Text-Property of the Label Control has to be set in the
OnPreRenderContent-Event.

After that changes all works fine.

Regards
Michael

Michael Schöller schrieb:
> Hi,
>
> I'm new to AJAX and has a little Problem to get an UpdatePanel inside
> an CustomServerControl to work.
> My goal is to create an CustomServerControl with an (at designtime)
> unknown number of UpdatePanels, that can be updated seperatly.
> Since I'm stuck I create a litte more static testproject to analyse
> the problem but I ran out of ideas what I could been missing.
> I would be realy glad if someone can show me hwo to get the
> UpdatePanels working.
>
> I created an ServerControl-Project called ServerControlTest and an ASP
> WebApplication called AXAJTest
> The Default.asxp looks like:
> --------------------------
> <%@ Page Language="C#" AutoEventWireup="true"
> CodeBehind="Default.aspx.cs" Inherits="AJAXTest._Default" %>
>
> <%@ Register assembly="ServerControlTest"
> namespace="ServerControlTest" tagprefix="cc1" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title></title>
> </head>
> <body>
> <form id="form1" runat="server">
> <asp:ScriptManager ID="ScriptManager1" runat="server">
> </asp:ScriptManager>
> <div>
> <asp:UpdatePanel ID="UpdatePanel1" runat="server">
> <ContentTemplate>
> <asp:Timer ID="Timer1" runat="server" Interval="1000"
> ontick="Timer1_Tick">
> </asp:Timer>
> <asp:Label ID="Label1" runat="server"
> Text="Label"></asp:Label>
> </ContentTemplate>
> </asp:UpdatePanel>
> </div>
> <cc1:ServerControl1 ID="ServerControl11" runat="server" />
> </form>
> </body>
> </html>
> ---------------------
> Code Behind looks like:
> ------------------------------------------------------
> using System;
>
> namespace AJAXTest
> {
> public partial class _Default : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> if(!IsPostBack)
> {
> ServerControl11.Text1 = DateTime.Now.ToString();
> ServerControl11.Text2 =
> DateTime.Now.AddDays(1D).ToString();
> }
> }
>
> protected void Timer1_Tick(object sender, EventArgs e)
> {
> Label1.Text = DateTime.Now.ToString();
> ServerControl11.Text1 = DateTime.Now.ToString();
> ServerControl11.Text2 = DateTime.Now.AddDays(1D).ToString();
>
> ServerControl11.TestPanel1.Update();
> }
> }
> }
> -----------------------------------------------
> The class ServerControl1 in ServerControlTest looks like this:
> ----------------------------------------------------------
> using System;
> using System.ComponentModel;
> using System.Web.UI;
> using System.Web.UI.WebControls;
>
> namespace ServerControlTest
> {
> [DefaultProperty("Text")]
> [ToolboxData("<{0}:ServerControl1
> runat=server></{0}:ServerControl1>")]
> public class ServerControl1 : WebControl
> {
> private UpdatePanel _testPanel1;
> private UpdatePanel _testPanel2;
>
> public UpdatePanel TestPanel1 { get { return _testPanel1; } }
> public UpdatePanel TestPanel2 { get { return _testPanel2; } }
>
> [Bindable(true)]
> [Category("Appearance")]
> [DefaultValue("")]
> [Localizable(true)]
> public string Text1
> {
> get
> {
> String s = (String)ViewState["Text1"];
> return (s ?? string.Empty);
> }
>
> set
> {
> ViewState["Text1"] = value;
> }
> }
>
> [Bindable(true)]
> [Category("Appearance")]
> [DefaultValue("")]
> [Localizable(true)]
> public string Text2
> {
> get
> {
> String s = (String)ViewState["Text1"];
> return (s ?? string.Empty);
> }
>
> set
> {
> ViewState["Text2"] = value;
> }
> }
>
> protected override void OnInit(EventArgs e)
> {
> base.OnInit(e);
> _testPanel1 = new UpdatePanel
> {
> ID = this.ID + this.IdSeparator + "UpdatePanel1",
> UpdateMode = UpdatePanelUpdateMode.Conditional,
> ChildrenAsTriggers = false,
> Page = this.Page
> };
> _testPanel2 = new UpdatePanel
> {
> ID = this.ID + this.IdSeparator + "UpdatePanel2",
> UpdateMode = UpdatePanelUpdateMode.Conditional,
> ChildrenAsTriggers = false,
> Page = this.Page
> };
> }
>
> protected override void RenderContents(HtmlTextWriter output)
> {
> Label label1 = new Label {ID = this.ID + this.IdSeparator +
> "Label1", Text = Text1};
> Label label2 = new Label {ID = this.ID + this.IdSeparator +
> "Label2", Text = Text2};
> _testPanel1.ContentTemplateContainer.Controls.Add( label1);
> _testPanel2.ContentTemplateContainer.Controls.Add( label2);
> _testPanel1.RenderControl(output);
> _testPanel2.RenderControl(output);
> }
> }
> }
> ---------------------------------------------------
>
> Regards
> Michael

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX Asyncfileupload - how to refresh updatepanel after UploadedComplete Mel ASP .Net 1 01-18-2012 05:20 PM
Triggering an UpdatePanel with a trigger located outside of the UpdatePanel Nathan Sokalski ASP .Net 1 06-15-2009 06:23 PM
ASP.NET AJAX : Dynamically Pushed JavaScript not working after being pushed to UpdatePanel's content Arachnid ASP .Net 0 10-05-2007 09:17 AM
refresh an updatePanel in an other updatePanel fran_j_diaz@yahoo.fr ASP .Net 3 08-08-2007 06:30 AM
AJAX UpdatePanel not resetting IIS Session =?Utf-8?B?TWlrZSBNY0FsbGlzdGVy?= ASP .Net 1 05-29-2007 08:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57