Showing posts with label placed. Show all posts
Showing posts with label placed. Show all posts

Wednesday, March 28, 2012

Accordian - Smooth at first, then gets choppy

Here's what I have. I've got an accordian in a web user control. And I've placed it on all my pages. When I go to the first page it runs VERY smooth.. but once I click on a link from the accordian to another page.. the refreshed accordian user control is all choppy.

I also tried this with a datagrid in an update panel as a user control and it did the same thing. So I know it's not the accordian. It has something to do with atlas. I compared the source from a smooth page and a choppy page and there's no difference..

so what do I have to do to keep it smooth? or can you not use it as a web user control?

Apparently.. it's all IE6's fault.. ugh that really sucks.. I don't know if I can get the whole company to upgrade to IE 7 Beta 3.. stupid flickering..
Hi unlikelyband,

Did you discover a specific reason IE6 was causing this? Or is it just only IE6 that it happens in?

Thanks,
Ted

Well. I actually only tried IE 6 and IE 7 Beta 3.. and IE 7 is really smooth..

I don't really have time to text IE 5 or opera or firefox..

All I know is that it kind of sucks people are going to have to deal with the flicker until they manage to upgrade everyone to IE 7


Hi,

Well it's true that the animation in IE6 isn't as smooth as IE7 and Firefox, but we're working on making the accordion snappier. Hopefully it won't be a problem for you and your users after the next release.

Thanks,
Ted

Accordian - Issue

Hi,

I placed a textbox and a button in an Accordian (inside a pane). When i clicked the button and sumbit the form the data in the textbox is gone. It happens only in the first post back. After that there is no issue.

Can someone kindly let me know if it is an issue or am I doing something wrong ? Do I have do some special configuration in the According control to be used effectively ?

Thanks

Rukshan

hi,

could you post .aspx and code behind code please.

thanks,

satish.


Hi Satish,

I had done a mistake in my post ealier. The problem occurs when you put the textbox and the button in a user control and place that user control inside an accordian pane.

Here is the code,

file : testusercontrol.ascx

<%@. Control Language="C#" AutoEventWireup="true" CodeFile="testusercontrol.ascx.cs" Inherits="testusercontrol" %>
<asp:TextBox runat="server" ID="TextBox1" />
<asp:Button runat="server" ID="submit1" Text="submit" />
<asp:Label runat="server" ID="label" ></asp:Label>

file: testusercontrol.ascx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class testusercontrol : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

submit1.Click += new EventHandler(sub_Click);

}

void sub_Click(object sender, EventArgs e)
{
label.Text = TextBox1.Text;
}
}

Here is the page where I have put the above usercontrol (there is no important code in the code behind for the page, so I am not going to put that here )

file: testatlas.aspx

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="testatlas.aspx.cs" Inherits="testatlas" %
<%@. Register src="http://pics.10026.com/?src=testusercontrol.ascx" TagName="testusercontrol" TagPrefix="uc1" %
<%@. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="Microsoft.Web.UI" TagPrefix="asp" %
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" 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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>

<div>
<cc1:Accordion ID="Accordion1" runat="server" SelectedIndex="0" Width="100%" Height="100%"

>
<Panes>
<cc1:AccordionPane ID="pane1" runat="server">
<Header>pane1</Header>
<Content>
<uc1:testusercontrol id="Testusercontrol1" runat="server">
</uc1:testusercontrol>
</Content>
</cc1:AccordionPane>

</Panes>
</cc1:Accordion>


</div>
</form>
</body>
</html>

The issue is when you enter some text on the textbox (which is in the usercontrol) and submit, the label should be populated with whatever you entered, but it does not :(.

It works fine when you put the user control outside of the according control.

Your help is highly appreciated.


Thanks

Rukshan


hi Rukshan,

i tried your code, but problem is i'm gettign error that Sys is not defined. when you run your project see in status bar of browser if you see something like "Done but with errors on page".

i'll try to see if it works.

thanks,

satish.


Hi Satish,

I do not get such an error in the browser.

Anyways, to reproduce the problem all you have to do it create a user control and put a textbox , a label and a button. In the button eventhandler, assign the the text in the textbox to the text property in the label.

Next create a page and put an accordian pane. Place the user control inside the accordian. Run the app.. When you click the button after entering some text in the textbox, idealy you should see that value in the label. But it doesn't . If you put the usercontrol outside the accordian, It works fine.

Hope you got the picture now :D

Thanks

Rukshan


I was able to duplicate your issue. It seems as if the accordion control is not preserving the view state of it's composite controls. I am not a control guru but it seems that accordion should derive from CompositeControl instead of WebControl. This would do two things - help with the view state of the controls and also clean up the design time rendering.

But back to your problem. The work around solution is to do the following if you want the viewstate for your user control maintained:

protected void Page_Init(object sender, EventArgs e) { AjaxControlToolkit.AccordionPane myPane =new AjaxControlToolkit.AccordionPane(); testusercontrol myUC = (testusercontrol)Page.LoadControl("~\\testusercontrol.ascx"); myPane.ContentContainer.Controls.Add(myUC); Accordion1.Panes.Add(myPane); } 

And then just do the following for the accordion in the ASP:

 <cc1:Accordion ID="Accordion1" runat="server" SelectedIndex="0" Width="100%" Height="100%"> <Panes> </Panes> </cc1:Accordion>  

Let me know how it goes.


Hi Cloris,


Thanks a lot, you solution works. Wonder what made it preserve the viewstate when the controls are added in code.

Anyways, it solves the problem. :D


Thanks again!

Cheers

Rukshan


I am not sure what caused this problem. I have been using the Accordion as my intro to web controls. I think it has something to do with the control and how it keeps track of where it's data is coming from - a datasource or the panes tags. When it tries to make the decision to reload the panes from the tags, it is not getting what it expects from the view state. So it just reloads the panes from scratch - killing the viewstate. There is some work that needs to be done in CreateChildControls and elsewhere. Definately a work in progress. The Accordion does function fine when attached to a datasource though.


Hi

Im new to this, i still dont get how this works? So do you HAVE to have your bits within a . ascx control in each pane and not just have a button to do something within the pane?

Also what do you need to put into your asp part of code so it knows where to look.

Thanks
Adam


Hi Adam,

You can just put your stuff within the pane. No need ot have a user control.

Thanks

Ruk


Thanks Ruk

But how do i set the code above to apply for my button control and not a usercontrol as explained earlier?

Thanks

Adam


Hi Adam,

I'm not sure if I understood your question properly, but I hope the following code would help

aspx file :

<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:Accordion ID="Accordion1" runat="server" SelectedIndex="0">
<Panes>
<cc1:AccordionPane runat="server" ID="pane1" >
<Header>
Pane 1
</Header>
<Content>

<asp:Button ID="Button1" runat="server" Text="Button" />
</Content>

</cc1:AccordionPane>
</Panes>
</cc1:Accordion>
</div>
</form>

code file :

protected override void OnInit(EventArgs e) {base.OnInit(e); Button btn = (Button) Accordion1.Panes["pane1"].FindControl("Button1"); btn.Click +=new EventHandler(btn_Click); }void btn_Click(object sender, EventArgs e) { Response.Write("Clicked me ! "); }
 
 
Thanks
Ruk 

That worked great, thanks!

Adam


Ok. But can you imagine this scenario.

1. First time I hit my page I render all accordion panes, with desired controls in it. Picture, Ajax.Rating control, ...)

2. Now I change some Rate in one of my panes. Page does PostBack

3. Now I can insert that rate in database, print message, do some logic...

4.problem: (I want everything that I binded in step 1 to see again after page is partially updated (I have Update Panel that wrap my accordion), That means I do not want again to bind my accordion panes, because this can be very time consuming!!!

5. My accordion does not show up.

Question: Am I missing something or have I logic error in my scenario?

Regards, Veroljub

Accessing the ScriptManager in code behind

In a User Control, how do you access the ScriptManager in code behind? The ScriptManager gets placed on the "parent" aspx page, but seems not to be accessible from any user controls ascx that get added to that page.

Specifically, I would like to capture the ScriptManager.PreRender event for use in a Repeater control.

Is there a way to raise an event in the parent ASPX page that the child user control can pick up?

if you want to call parent control,

you can use

this.Parent.FindControl..

i am not sure why you want user control to do something with "ScriptManager.PreRender event"

why cant you use ScriptManager.PreRender event to do something for your user control ?

you can always use

Page.FindControl to call your use control in the ScriptManager.PreRender event


Hey, thanks for your reply. I could really use some help.

The goal is to use an update panel inside a repeater, both of which are use controls loaded onto a page. There are some inherint challenges with this. The first being that 1) the ScriptManager is not accessible because it is in the parent, 2) the update panel elements don't seem available at the time of the event. Below is my code to access them, but the me.parent.findcontrol always returns "nothing."

My research has shown me that the ScriptManager.PreRender is the event that I can access/ change these values.

My entire page works great, except the update panel inside the repeater does not update and I cannot access the objects within it (i,e, a label)

Sub handleTypeTest(ByVal senderAs System.Object,ByVal eAs System.EventArgs)

Try

Dim tempVAsString = ddlAnswerType.SelectedValue

ddlAnswerType.Visible =False

Dim tempUPAs UpdatePanel =Me.Parent.FindControl("upDropDowns")

IfNot tempUPIsNothingThen tempUP.Update()

Dim tempLabelAs Label =CType(Me.Parent.FindControl("lblTest"), Label)

tempLabel.Text ="changed"

Catch exAs Exception

EndTry

EndSub

Accessing Masterpage Ajax control from Web user control

Hi all,

I have created a master page in asp2.0 and i have placed ModalPopupExtender in that. I have written a custom Textbox control. In that text Changeded event i have created reference to the Masterpage modalpopupextender using Findcontrrol method. But i cant able to loop through tge Master page controls Properly. I am unable to findthe controls with its client id. Can anybody know how to solv this.

My aim is to call the modalpopupextender show event from the custom control.

<cc1:ModalPopupExtenderID="ModalPopupExtender1"runat="server"TargetControlID="btnForLookup"PopupControlID="LookupPanel"BackgroundCssClass="modalBackground">

Private

Sub AHNLookup_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Click

{ Dim contr as ModalpopupExtender

Contr = Me.page.master.FindControls("ModalPopupExtender1")

Constr.show() -->Gives error as Null object.

}

====

Thanks in advance.

S.Sathishraja

Hi,

Please try to find it in a recursive way.

public?Control FindControlRecursive(Control root, string id)
{
????if (root.ID == id)
????{
????????return root;
????}

????foreach (Control c in root.Controls)
????{
????????Control t = FindControlRecursive(c, id);
????????if (t != null)
????????{
????????????return t;
????????}
????}

????return null;
}
Hope this helps.

Accessing controls within in an Accordion ?

Hi all,

A simple problem : I can't get access by to a control placed within a Accodion pane.

More exactly, code completion in C# is giving me the name of the component (a Literal within a Pane of an Accordion) but at runtime I get an error (null reference), the Literal is not created, whatever the moment I try to catch it.

I tried a lot of different events (of the Page, of the Accordion..), I tried to use FindControl instead of direct acces to "Literal1", all failled..

I need to dynamicaly load the content of a Pane when the Page is rendered. I generaly use a Literal since I inject html code. What is the trick to access an asp control within an Accordion Pane ??

Thanks in advance for your help.

The easiest solution would be using FindControl(). Have a look at the following example:

.aspx page:

<%

@.PageLanguage="C#"%>

<%

@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="ajaxCT" %>

<!

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"/>

<

body><formid="form1"runat="server"><asp:ScriptManagerID="smr"runat="server"></asp:ScriptManager>

<

ajaxCT:AccordionID="Accordion1"runat="server"><Panes><ajaxCT:AccordionPaneID="AccordionPane1"runat="server"><Header>Header-1</Header><Content>

<asp:GridViewID="GridView1"runat="server"></asp:GridView>

</Content></ajaxCT:AccordionPane></Panes>

</

ajaxCT:Accordion></form>

</

body>

</

html>

.cs file(code behind):

protectedvoid Page_Load(object sender,EventArgs e)

{

GridView myGridView = AccordionPane1.FindControl("GridView1")asGridView;

myGridView.DataSource= myDataTable; // myDataTable is defined somewhere else

myGridView.DataBind();

}

Hopefully this would be helpful.

Cheers.

Sazzad

Wednesday, March 21, 2012

A bug? None-Stop Timer~~Need Help!

I placed a timer in an update panel, and add a trigger to the update panel. when a button clicked the trigger raised and the timer enabled, once again clicked the button, the timer have should be stopped, but it still works. click again! It seems there's a new timer and the old timer works, too~~~~

It is a bug? the following is the code.

=========================================

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

<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True">
</atlas:ScriptManager>
<div>
<atlas:UpdatePanel ID="upTimer" runat="server" EnableViewState="True" Mode="Conditional">
<ContentTemplate>
<atlas:TimerControl ID="timerProgress" runat="server" Enabled="false" EnableViewState="False" Interval="1000" OnTick="timerProgress_Tick">
</atlas:TimerControl>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="cmdStart" EventName="Click" />
<atlas:ControlEventTrigger ControlID="cmdCancel" EventName="Click" />
</Triggers>
</atlas:UpdatePanel>
<atlas:UpdatePanel ID="upProgress" runat="server" EnableViewState="True" Mode="Conditional">
<ContentTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="timerProgress" EventName="Tick" />
<atlas:ControlValueTrigger ControlID="timerProgress" PropertyName="Interval" />
</Triggers>
</atlas:UpdatePanel>
<atlas:UpdatePanel ID="upButtons" runat="server" Mode="Conditional">
<ContentTemplate>
<asp:Button ID="cmdStart" runat="server" EnableViewState="False" OnClick="cmdStart_Click"
Text="开始上传" />
<asp:Button ID="cmdCancel" runat="server" OnClick="cmdCancel_Click" Text="取消上传" Visible="False" />
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="cmdStart" EventName="Click" />
<atlas:ControlEventTrigger ControlID="cmdCancel" EventName="Click" />
</Triggers>
</atlas:UpdatePanel>

</div>
</form>
</body>
</html>
=========================================

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void cmdStart_Click(object sender, EventArgs e)
{
cmdStart.Visible = false;
cmdCancel.Visible = true;
timerProgress.Enabled = true;
}
protected void cmdCancel_Click(object sender, EventArgs e)
{
cmdStart.Visible = true;
cmdCancel.Visible = false;
timerProgress.Enabled = false;

}
protected void timerProgress_Tick(object sender, EventArgs e)
{
CheckBox1.Checked = !CheckBox1.Checked;
}
}

I am having the same problem. The timer cannot be turned off - even if the timer itself is placed inside the updatepanel. Often what you wanna do is have the update panel update every x seconds while some task is running, and then be turned off.

Any suggjestions on how to disable the timer? - (or is this a bug) ?


There are several issues with the TimerControl and partial rendering. I solved the problem by writing a custom control. Copy the code from this snippet to a file in your App_Code directory

using System;using Microsoft.Web.UI.Controls;namespace CustomControls{ /// /// Summary description for StoppableTimer /// public class StoppableTimer : TimerControl { public StoppableTimer() { } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (this.Page.IsPostBack) { this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "TimerStop", "Web.Application.findObject('" + this.ClientID + "').set_enabled(" + (this.Enabled ? "true" : "false") + ");" , true); } } protected override void RenderScript(Microsoft.Web.Script.ScriptTextWriter writer) { writer.WriteStartElement("timer"); writer.WriteAttributeString("id", this.UniqueID); writer.WriteAttributeString("interval", this.Interval.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteAttributeString("enabled", this.Enabled.ToString()); writer.WriteStartElement("tick"); writer.WriteStartElement("postBack"); writer.WriteAttributeString("target", this.UniqueID); writer.WriteAttributeString("argument", string.Empty); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); } }}
Next register this custom control as a tag and use it.
<%@. Page Language="C#" AutoEventWireup="true" CodeFile="TimerTest.aspx.cs" Inherits="Default2" %><%@. Register TagPrefix="AppCode" Assembly="App_Code" Namespace="CustomControls" %><!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>Untitled Page</title></head><body> <form id="form1" runat="server"> <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"> </atlas:ScriptManager> <div> <atlas:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <span id="Span1" runat="server"></span> <AppCode:StoppableTimer runat="server" ID="Timer1" Interval="1000" Visible="true" OnTick="Timer1_Tick"> </AppCode:StoppableTimer> </ContentTemplate> <Triggers> <atlas:ControlEventTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </atlas:UpdatePanel> </div> </form></body></html>

When the issues with Atlas timer control are fixed in a release you can simply replace AppCode:StoppableTimer with atlas:TimerControl.


how to use your custom control in an application like : to fetch the data without postback at a regular interval and depending upon some condition need to stop the timer so that we can stop data fetching operation?

Jaideep


Nice pice of code Rama Krishna.

I tried to modify your component to Marts CTP, but I cant get it to work. Writing the following:

writer.WriteAttributeString(

"id", UniqueID);

Will result in a assertion error from atlas - stating that the control is dublicate (it is not - looking at the source) - and the script (set_enabled part) will set the xml enabled = false - but the update continues. Im having a hard time - anyone got this to work?

Here is my (not functional) Marts CTP version of the control - what am I doing wrong here ?

public

classStoppableTimer :TimerControl {public StoppableTimer() {

}

protectedoverridevoid OnPreRender(EventArgs e) {base.OnPreRender(e);if (Page.IsPostBack) {

Page.ClientScript.RegisterStartupScript(Page.GetType(),

"TimerStop","Sys.Application.findObject('" + UniqueID +"').set_enabled(" + (Enabled ?"true" :"false") +");"

,

true);

}

}

protectedoverridevoid RenderScript(Microsoft.Web.Script.ScriptTextWriter writer) {

writer.WriteStartElement(

"timer");

writer.WriteAttributeString(

"id", UniqueID);

writer.WriteAttributeString(

"interval", Interval.ToString(System.Globalization.CultureInfo.InvariantCulture));

writer.WriteAttributeString(

"enabled", Enabled.ToString());

writer.WriteStartElement(

"tick");

writer.WriteStartElement(

"postBack");

writer.WriteAttributeString(

"target", UniqueID);

writer.WriteAttributeString(

"eventArgument",string.Empty);

writer.WriteEndElement();

writer.WriteEndElement();

writer.WriteEndElement();

}

}


This solved my problem of the timer not writing out an ID when its created on the server. Also I'm very happy there is a script writer.

protected override void RenderScript(Microsoft.Web.Script.ScriptTextWriter writer)

Thanks.


Thank you everyone who contributed in previous posts

I've got this workn with March CTP in internet explorer 6

Its mostly the same but my main goal was to create a timer on the server and be able to stop and start it on the client and there was no clientid there. Argh I already have vb in app_code so its now vb and it has a Namespace to match my other Atlas stuff.

Heres the prerender routine. First off I'm adding a script to use on the client to start and stop the timer. Since I check the result of the findobject I don't bother checking for postback and I use enabled.tostring.tolower instead of the inline if.

Imports

Microsoft.VisualBasic

Imports

Microsoft.Web.UI.Controls

Namespace

DWS.Web.AtlasProtectedOverridesSub OnPreRender(ByVal eAs System.EventArgs)IfNotMe.Page.ClientScript.IsClientScriptBlockRegistered(Me.GetType,"DWSTimerStartStop")ThenDim sbAsNew StringBuilder

sb.Append(

"function DWSTimerStartStop (clientid,boolstop){")

sb.Append(

"var s = Sys.Application.findObject(clientid);")

sb.Append(

"if (s) {s.set_enabled(boolstop)};")

sb.Append(

"}")

Page.ClientScript.RegisterClientScriptBlock(

Me.GetType,"DWSTimerStartStop", sb.ToString,True)EndIfIfNotMe.Page.ClientScript.IsStartupScriptRegistered(Me.GetType,"DWSTimerStartStop" &Me.ClientID)ThenDim sbAsNew StringBuilder

sb.Append(

"DWSTimerStartStop(""" &Me.ClientID &""",")

sb.Append(

Me.Enabled.ToString.ToLower)

sb.Append(

");")

Page.ClientScript.RegisterStartupScript(

Me.GetType,"DWSTimerStartStop" &Me.ClientID, sb.ToString,True)EndIfMyBase.OnPreRender(e)EndSub

I think everyone had the renderscript. I put a MS timercontrol on the page and checked the render xml-script side by side (view source on browser) so I could compare the groups control output with that of Atlas.

ProtectedOverridesSub RenderScript(ByVal writerAs Microsoft.Web.Script.ScriptTextWriter)

writer.WriteStartElement("timer")

writer.WriteAttributeString("id",Me.ClientID)

writer.WriteAttributeString("interval",Me.Interval.ToString(System.Globalization.CultureInfo.InvariantCulture))

writer.WriteAttributeString("enabled",Me.Enabled.ToString())

writer.WriteStartElement("tick")

writer.WriteStartElement("postBack")

writer.WriteAttributeString("target",Me.UniqueID)

writer.WriteAttributeString("eventArgument",String.Empty)

writer.WriteEndElement()

writer.WriteEndElement()

writer.WriteEndElement()

EndSub

EndClass

I was going for server so here's a server example

PartialClass C_photo

Inherits DWS.Web.WebParts.WebPartBasectrl

'here it is

PrivateWithEvents txAsNew DWS.Web.Atlas.TimerControl

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

'Set timer interval

tx.ID =

"dan1"

tx.Interval = 5000

Me.Controls.Add(tx)'Here are my two controls that operate on the client. They use the script generated in the control prerender.

Dim xAsNew HtmlButton

x.InnerText ="stop"

x.Attributes.Add(

"onclick","DWSTimerStartStop(""" & tx.ClientID &""",false)")Me.Controls.Add(x)Dim yAsNew HtmlButton

y.InnerText =

"start"

y.Attributes.Add(

"onclick","DWSTimerStartStop(""" & tx.ClientID &""",true)")Me.Controls.Add(y)EndSub

EndNamespace

And of course the group goal of having the enabled works too.

Protected

Sub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.ClickIf Button1.Text ="Stop"Then

Button1.Text =

"Play"

tx.Enabled =

FalseElse

Button1.Text =

"Stop"

tx_Tick(sender, e)

tx.Enabled =

TrueEndIfEndSub

Thank you to whoever started this thread.

Thank you to the scriptwriter example.

Thank you eventArgument fix.

DWS


I just started using Atlas with the April CTP. I'd really like to have the ability to cancel the timer. I can't seem to get this to work though. I converted the code in the previous post to C#. I think that went ok.

Should the Timer control be incuded in the UpdatePanel or should it be outside the panel?

Thanks,

Andy


hello.

i'd put it out...btw, there's another thread on this forum (it's huge, maybe 3 pages now) that shows another option to clear a timer from a page.


Rama Krishna, this was very helpful!

I modified the code a bit to work with the April CTP, and added a few client side APIs to pause, resume and toggle the timer. Here is the modified code:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.Controls;

namespace Yadda.Web.UI.WebControls {

/// <summary>
/// This is a workaround for an issue in the June CTP of Atlas - the provided TimerControl cannot be stopped or paused
/// by the client.
/// This is based on code from Rama Krishna, http://forums.asp.net/1222935/ShowPost.aspx
/// This one inherits from the provided TimerControl and fixes these issues.
/// Once this is fixed in Atlas this control should be removed and replaced with the standard one.
/// Client-side API:
/// TimerToggle(clientID) - toggles the timer between off and on state
/// TimerPause(clientID) - temporarily pause the timer; no events will be fired until TimerResume will be called.
/// TimerResume(clientID) - resumes a paused timer; Can be safely called multiple times.
/// </summary>public class TimerControlWithPause : TimerControl {
public TimerControlWithPause() {
//
// TODO: Add constructor logic here
//}protected override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
// Render client-side APIs:this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(),"TimerToggle",
"function TimerToggle(clientId) {" +
"var timerObj = $object(clientId); " +
"if (!timerObj) return; " +
"if (timerObj.get_enabled()) TimerPause(clientId); else TimerResume(clientId); " +
"}" +
"function TimerPause(clientId) {" +
"var timerObj = $object(clientId); " +
"if (!timerObj) return; " +
"timerObj.set_enabled(false); " +
"}" +
"function TimerResume(clientId) {" +
"var timerObj = $object(clientId); " +
"if (!timerObj) return; " +
"timerObj.set_enabled(true); " +
"}",
true);// This will sync the client side state with the server state on postbacks:if (this.Page.IsPostBack) {
this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(),"TimerStop",
(this.Enabled ?string.Format("TimerResume('{0}');",this.ClientID) :string.Format("TimerPause('{0}');",this.ClientID))
,true);
}
}

protected override void RenderScript(Microsoft.Web.Script.ScriptTextWriter writer) {
writer.WriteStartElement("timer");
writer.WriteAttributeString("id",this.ClientID);
writer.WriteAttributeString("interval",this.Interval.ToString(System.Globalization.CultureInfo.InvariantCulture));
writer.WriteAttributeString("enabled",this.Enabled.ToString());
writer.WriteStartElement("tick");
writer.WriteStartElement("postBack");
writer.WriteAttributeString("target",this.UniqueID);
writer.WriteAttributeString("eventArgument",string.Empty);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
}
}
}


Nice solution yanivgolan. This is working great.


I'm still waiting for Visual Web Developer to finish installing- I have no experience with Atlas and very little ASP.net experience and this thread is a little old, but it sounds like the timer thing is a bug that will be fixed in future versions of Atlas, so a lot of these workarounds seem a little convoluted... wouldn't the following workaround be good enough for most applications until Atlas fixes itself??:

protected void timerProgress_Tick(object sender, EventArgs e)
{

If (timerProgress.Enabled )
CheckBox1.Checked = !CheckBox1.Checked;
}


When I use code similar to this... (I've actually tried it a few different ways now...) It compiles and runs fine under VS 2005's internal web... But when I try to publish it and run it from any other stand alone web server (including the IIS on the same box the VS 2005 is on) I get an error when I try to load the page:

Compilation Error

Description:An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message:CS0117: 'ASP.default_aspx' does not contain a definition for 'myTimer_Tick'

Source Error:


Line 16: </atlas:ScriptManager>
Line 17: <div>
Line 18: <AppCode:StopableTimer runat="server" ID="myNewTimer" Enabled="false" Interval="900" OnTick="myTimer_Tick">
Line 19: </AppCode:StopableTimer>


Does anyone have any sort of suggestion as to why this may be happening, and how I might fix it..?

Any thoughts or suggestions would be very much appreciated!

Thanks! ;)

- Andrew

hello.

according to the error message, it seems like the myTimer_Tick method isn't being found. where have you defined it?


Hello,

Thanks for the reply...

Of course... myTimer_Tick -has- to be defined, or it would not run under Visual Studio, right? ;)

But you're right in that it seems it isn't being found.. but why not..?

It is defined in the Default.aspx.cs file - referenced as the "CodeFile" at the top of the Default.aspx file. Here's the top two lines of my Default.aspx file:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@. Register TagPrefix="AppCode" Namespace="MyCustomControls" %
The Namespace is where the StoppableTimer is that's similar to the code a few posts above, which I got from:

http://runithomsen.blogspot.com/2006_03_01_runithomsen_archive.html

Do I need to define it some other way..? It still doesn't make sense (to me!) that it works under Visual Studio's internal web browser, but not when I publish it to an IIS server. :(

Any thoughts or suggestions would be appreciated! :)

Thanks!

Cheers

- Andrew