Showing posts with label creating. Show all posts
Showing posts with label creating. Show all posts

Wednesday, March 28, 2012

Multiple Timers and Multiple UpdatePanels

I am creating a page with many different server controls that each need to automatically refresh independently. I want the developer to be able to specify the refresh time, so I am exposing that as a property of the control. The problem is, whenever the first timer ticks, all the other timers reset (and the label control in each UpdatePanel updates with the current time) even though they are on different intervals. It acts like all the UpdatePanels are posting back, but I know the tick event is only firing on the first timer (the one with the lowest interval). Any ideas as to what's happening here or what I'm doing wrong?

Here is my (raw, not refactored) code (CreateChildControls method):

If AutoUpdateThen Dim panelAs UpdatePanel =New UpdatePanel()Dim progressAs UpdateProgress =New UpdateProgress() _label =New WebControls.Label()Dim timerAs Timer =New System.Web.UI.Timer() panel.ID =Me.ID +"_UpdatePanel" panel.ChildrenAsTriggers =True panel.UpdateMode = UpdatePanelUpdateMode.Conditional timer.ID = panel.ID +"_RefreshTimer"#If DEBUG Then timer.Interval = IIf(RefreshSeconds <> 0, RefreshSeconds, _refreshMinutes)#Else timer.Interval = _refreshMinutes#End If AddHandler timer.Tick,AddressOf OnTimerTick panel.ContentTemplateContainer.Controls.Add(timer) _label.Text =String.Format("Updated at: {0}", DateTime.Now) panel.ContentTemplateContainer.Controls.Add(control) panel.ContentTemplateContainer.Controls.Add(_label) control = panelEnd If
I've also tried creating the timers outside the UpdatePanels and adding an ASyncPostBack trigger on the Tick event of each timer like so:
 
If AutoUpdateThen Dim panelAs UpdatePanel =New UpdatePanel()Dim progressAs UpdateProgress =New UpdateProgress()Dim timerTriggerAs New AsyncPostBackTrigger() _label =New WebControls.Label()Dim timerAs Timer =New System.Web.UI.Timer() panel.ID =Me.ID +"_UpdatePanel" panel.ChildrenAsTriggers =False panel.UpdateMode = UpdatePanelUpdateMode.Conditional timer.ID = panel.ID +"_RefreshTimer"#If DEBUG Then timer.Interval = IIf(RefreshSeconds <> 0, RefreshSeconds, _refreshMinutes)#Else timer.Interval = _refreshMinutes#End If timerTrigger.ControlID = timer.ID timerTrigger.EventName ="Tick" Controls.Add(timer) panel.Triggers.Add(timerTrigger) _label.Text =String.Format("Updated at: {0}", DateTime.Now) panel.ContentTemplateContainer.Controls.Add(control) panel.ContentTemplateContainer.Controls.Add(_label) control = panelEnd If
Thanks! 

D'oh!


A detail I had failed to mention previously was that these update panels are contained within a surrounding update panel. This panel was set to UpdateMode = Always, which was causing all of the UpdatePanels inside of it to automatically update. I set it to conditional and it seems to work fine now.

-Joe

Saturday, March 24, 2012

Mystery of the Un-positionable DragPanel!

I am creating a portal page for my company's intranet, a la Google homepage. Since DropZones seem like such a pain to work with, I decided to take a different approach to the widget movement, and use Javascript. My idea requires that I move a Panel (which also happens to be the subject of the DragPanelExtender) using "Style:top" and "Style:left". The problem is, I can't seem to get this to work, no matter how I form the line.

 function adjustToColumn(e){
//get location var widg= getWholeWidgetOnDrop(e); var location= $common.getLocation(widg); x= location.x; y= location.y; alert(x +"," + y);
//set location

//widg.style("top","100px"); //, "100px");
//widg.Attributes.CssStyle.Add("top", "100px");
}

 
In the above code, 'getWholeWidgetOnDrop' returns the outermost panel containing the entire widget.
The 'get' portion of this code works just fine.
However, no matter how I form the 'set' portion, I always seem to get an error.
I've tried widg.Attributes.Style.Add, widg.Attributes.Add, among countless others, and they always come back
saying that either 'Attributes... is null or not a method" or "Object does not have this method or property"
I'm all out of ideas! 
 Help please?!Big Smile 

Hello,

Use the Javascript debugger in your set call with the line 'debugger;'.

Then, add the widg variable to the watch window. I believe you will need 'widg.style.top'. Check out jquery as well for manipulating dom objects.

Regards,

Louis


Thanks for the reply.

I tried widg.style.top, and unfortunately it didn't work either...

However, this morning, I ran across another command that DID work. I used Sys.UI.DomElement.setLocation(element, x, y) ; This worked like a CHAMP. Supposedly, you can abbreviate this by using $common.setLocation(element, x, y); but for some reason or the other, this didn't work for me.

I appreciate the help, though!

--Dustin

Need dunamic Handle in AjaxControlToolkit.SliderExtender

Trouble is in the creating the Slider where Rail parted the Handel into two part with the different colors where color is generated according to Value

Hi,

My idea is you may add a valueChanged handler to the SliderBehavior component, and set the the color according to the value.

For instance:

<ajaxToolkit:SliderExtenderBehaviorID="slider"ID="SliderExtender1" runat="server" TargetControlID="TextBox1"
Minimum="0" Maximum="100" RaiseChangeOnlyOnMouseUp="true" Steps="5" RailCssClass="myclass" HandleImageUrl="../images/edit.gif">
</ajaxToolkit:SliderExtender>

function pageLoad(){

var slider = $find("slider");

slider.add_valueChanged(onValueChanged);
}

function onValueChanged()

{

var slider = $find("slider");
if(slider.getValue() > ? )

slider.set_RailCssClass(//a css class with a different back color);

}

Hope this helps.