Showing posts with label timer. Show all posts
Showing posts with label timer. Show all posts

Wednesday, March 28, 2012

Postback sees TextChanged event while timer initiated the postback


Hi,

I have a challenge which I cannot seem to master and I hope that somebody already solved it.

Here is the setup to create the issue:

Place an updatepanel on a page, place a timer control inside (or outside with a trigger section for the panel), set the interval to 3000 or so and enable the timer.

Then place a TextBox on the page and add some code to the TextChanged event.

Now start the page..

Type some text in the textbox but don't press enter, when the timer fires you will find that the TextChanged event comes in through the postback.

I think I have tried everything, partialrendering to true, updatemode to conditional, childelementsastriggers to false and so on...

I need the text entered in the textbox to stay as it is until the moment the user presses enter, while the update panel constantly refreshes a datagrid.

Does anybody have a solution? Would I need to use a javascript timer which updates the datagrid? would that prevent a postback?

Please help...

Thanks

Is the textbox inside the updatepanel?

If your expecting the user to hit enter, presumably that triggers a click event for a button. Why not read/process the textbox's value as part of the button's click event and avoid TextChanged altogether?


Inside or outside renders the same problem.

The thing is that when a user enters some text in the textbox but is not finished typing yet, the timer causes a postback which in turn results in the TextChanged event, but the user is not ready to post yet.


Yeah i'd say this is by design and theres nothing you can do about it. Modify your approach so it doesn't make use of the TextChanged event (as i suggested in previous post).


If you can put the DataGrid and TextBox in separate UpdatePanels, that would begin to solve the problem.


Ha, I won't sacrefice design over some "feature". I won't believe that this behaviour is by design and if it is then there must be a way to intercept the event..

Hmm... I may have solved my own problem.

P.S. the TextChanged event is needed as we are using barcode scanners which add a carriage return to the end of the text stream which triggers the TextChanged event just nicely. The user should also be able to enter some code without hitting a button as confirmation..

Thanks,

Wouter


I'm not sure how multiple UpdatePanels would change your design, since you didn't post any sample code.

You may want to take a closer look at how UpdatePanels work. What you're describing is the inevitable consequence of putting a timer on an UpdatePanel that contains data entry fields.

Posting On Ajax Help Required.

Hi All,

My requirement is like displaying random advertisements in masterpage. I had a page with Ajax Timer control which on Timer_Tick event fetches me a new image and bind to <asp:hyperlink>, my problem is on page_load also i want to display image, but image is displayed only on Timer_Tick after some fixed 3000 seconds is elapsed. On page_load i want to display same images, my images are dynamic comes from database, i store them in a dataset, and binds to asp:hyperlink on timer_tick. Can anyone help, on how to display image on page_load, is there any way how i can attach the server side event (Timer_Tick) on page_load also, so that it will fetch me the image.

Thanks In Advance,

Karthikeyan.

Consider using the AdRotator control.

The AdRotator control selects and displays an ad randomly each time a page is refreshed.

The AdRotator control in ASP.NET 2.0 populates its image and navigation properties in 3 different ways -
Database, XML and also programmatically.

Check these links for more info & code samples -
http://www.ipona.com/samples/0321257278/11/AdRotator-Bound.aspx
http://www.ipona.com/samples/0321257278/SourceViewer/SrcView.aspx?file=/samples/0321257278/11/AdRotator-Bound.aspx
http://www.c-sharpcorner.com/UploadFile/mahesh/adrotator06142007110621AM/adrotator.aspx
http://blogs.msdn.com/acoat/archive/2005/11/07/AdRotator-Dynamic-Image-Generation.aspx


Thanks for your valuable suggestion, but my requirement is i don't want to do a postback for whole page, just for banner, what i want is to do a Asynchronous postback on fixed timer interval and change banner. First time when the page load there is no banner getting displayed. This is my problem, is there any way through which i can again call Timer_Tick event in page_load so that for the first time a image will be loaded.

Thanks & Regards,

karthikeyan.

Prefetching Images

I am using the update panel, and the timer control to automatically change a person's profile text, and their photo (small 65x65 pixels). Everything works well so far, except the transition is not always smooth for the photo.

Before the images/photos become cached in the browser, the default broken (link-to-image) image shows up, before the relevant photo loads. After that image loads the first time, the transition is smooth.

Is there a way to prefetch these images (approximately 8) when the page loads?

Thanks,

Karls

The easiest way I know of is to create a .js function to preload the images. Something like:

function preload(){
var imageUrls = ["img1.jpg","img2.jpg","img3.jpg"];
var images = [];
for(var i=0;i<imageUrls.length;i++){
var image = new Image();
image.src = imageUrls[i];
images.push(image);
}
}

That you'd call that function during pageLoad(). Setting the 'src' of the image object should cause the browser to start downloading that image.


Nice,

I would like to try that, but I am having a problem converting this to VB. Can anyone convert this?Huh?


No, i'ts javascript.


Ahh, makes sense now.

Thanks.

Monday, March 26, 2012

PROBLEM - Timer Control calling Web Service?

Hi,

I have an issue, where I need to utiliize the AJAX Timer Control to continously poll an AJAX Web Service. Now I have successfully been calling the Web Service directly from Javascript, without any issue, however I need to perform some server-side actions.

Hence i need to use the Timer control to perform a onTick event call, which uses the same AJAX Web Service on the server side as follows:

iWebService ws = new iWebService();

string response = ws.iFunction("some data");

The problem here is i recieve the following error on every interval call from the Timer;

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occured while processing the request on the server. The status code returned from the server was: 500

If anyone can help here, then that would be great, otherwise a temporary solution for my problem is to get the Timer to call a client side function instead of the server side one, and then for me to make a traditional Javascript request to the Web Service. If anyone knows how to do this, I would be very greatful.

Thank you!

We'd need to see some code to figure out what's going on, but rather than using the server Timer control, you're probably better off downloading the Futures January CTP and using the Sys.Preview.Timer control in there.

Hi, Steve

<formid="mainform"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"><Services><asp:ServiceReferencePath="iWebService.asmx"/></Services></asp:ScriptManager><asp:Timerid="timToolBar"runat="server"OnTick="Refresher"Interval="5000"></asp:Timer><asp:UpdatePanelID="upToolBar"runat="server"UpdateMode="Conditional"><Triggers><asp:AsyncPostBackTriggerControlID="timToolBar"/></Triggers><ContentTemplate><uc2:ctrlToolBarID="ToolBar"runat="server"/></ContentTemplate></asp:UpdatePanel>
//CODE BEHIND FILE 

protected void Refresher(object sender, EventArgs e)

{

iMediaService ws =newiMediaService();

string response = ws.GetEvent(sessionid.Value, 2000);

//Some code here to update the Toolbar

}

It's pretty simple to be honest, the call to the WS basically returns some info I use to update the ToolBar. I need to call the WS continuosly, but information is only returned if the iWebService.RegisterClient is called first, before this, the call to GetEvent returns an empty string, which is correct. But after the RegisterClient has been called, i should get some data back from every call to the ws.GetEvent function.

Simple Call Logic

1. Register Client

2. Repeat call to GetEvent & Update ToolBar

The first call to GetEvent after the RegisterClient works fine and i recieve the correct data, but after that, when the Timer fires every interval, i get that error message. The ToolBar is a Web User Control, now simply I could just output the response string from GetEvent to a TextBox for testing, but like i said, the first call is fine, after that it just throws that error.

Also as i was debugging this, the debugger was not breaking on my breakpoint on the first line of the Refresher function, i think theres a problem after i write some info to the ToolBar.


The 500 suggests that something's breaking on the server. I would recommend grabbingNikhil's Web Development Helper and taking a look at the request and 500 response. It's quite likely the contents of the response will show you exactly what the problem is.

(As it is, I can't really guess what's going wrong.)

Saturday, March 24, 2012

Problem by using adrotator and timer control for an atlas project

Hello.
I want to show the advertisements without page posting. I have an adrotator,an xml file,timer control,and an update panel. When I run the project only one advertisement is shown on the page then the page is blank.
My aspx.pages codes:

<div>
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True">
</atlas:ScriptManager>
<atlas:TimerControl ID="TimerControl1" Interval="2000" runat="server" />
<atlas:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/ads.xml" />
</ContentTemplate>
</atlas:UpdatePanel>
</div
and ads.xml

<?xml version="1.0" encoding="utf-8" ?
<Advertisements>
<Ad>
<ImageUrl>Images/Book1.jpg</ImageUrl>
<NavigateUrl>http://www.Amazon.com/Book1.aspx</NavigateUrl>
<AlternateText>Book1</AlternateText>
<Impressions>2</Impressions>
<Keyword>Book</Keyword>
</Ad
<Ad>
<ImageUrl>Images/Book2.jpg</ImageUrl>
<NavigateUrl>http://www.Amazon.com/Book2.aspx</NavigateUrl>
<AlternateText>Book2</AlternateText>
<Impressions>2</Impressions>
<Keyword>Book</Keyword>
</Ad
<Ad>
<ImageUrl>Images/Book3.jpg</ImageUrl>
<NavigateUrl>http://www.Amazon.com/Book3.aspx</NavigateUrl>
<AlternateText>Book3</AlternateText>
<Impressions>3</Impressions>
<Keyword>Book</Keyword>
</Ad
<Ad>
<ImageUrl>Images/Book4.jpg</ImageUrl>
<NavigateUrl>http://www.Amazon.com/Book4.aspx</NavigateUrl>
<AlternateText>Book4</AlternateText>
<Impressions>3</Impressions>
<Keyword>Book</Keyword>
</Ad
</Advertisements
can you help me?The timer isn't in the UpdatePanel so you need to add the Tick event as a trigger.
Thanks for your reply but I tried it before too.
my aspx pages codes:

<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" >
<ErrorTemplate>
There was an error processing your action.<br />
<span id="errorMessageLabel"></span>
<hr />
<button type="button" id="okButton">OK</button>
</ErrorTemplate>
</atlas:ScriptManager>
<atlas:TimerControl ID="TimerControl1" Interval="2000" runat="server" OnTick="TimerControl1_Tick" />
<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional" >
<ContentTemplate>
<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/Reklam2.xml" />
</ContentTemplate>

<Triggers>
<atlas:ControlEventTrigger ControlID="TimerControl1" EventName="Tick" />
</Triggers>
</atlas:UpdatePanel
timer tick event

protected void TimerControl1_Tick(object sender, EventArgs e)
{
UpdatePanel1.Update();
}

what is the wrong , I can not find the problem.
waiting for your reply...

Hello,

Is there anybody who can help me about this problem?


help,where is the error?
Hello,I solved the problem.

My aspx page

<form id="form1" runat="server">
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" />
<br />
<atlas:TimerControl ID="TimerControl1" runat="server" Interval="2000">
</atlas:TimerControl>
<br />
<div>
<atlas:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/Reklam.xml" />
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="AdRotator1" EventName="AdCreated" />
</Triggers>
</atlas:UpdatePanel>
</div>
</form
I added a trigger.
<Triggers>
<atlas:ControlEventTrigger ControlID="AdRotator1" EventName="AdCreated" />
</Triggers>
Help of this trigger,when a new advertisement is taken,updatepanel is updating. So without refreshing advertisements are shown on the web site. Reklam.xml is similar to ads.xml, only the name is Turkish.


Thanks for your example, i follow your example to solved my problem:)
not matter

Wednesday, March 21, 2012

Problem in Reloadind a GridView using Timer

Hi,

Iam new to ASP.net. I have a problem; I need to reload a gridview forevery five seconds. So, I am using a timer control. In thetimerconrol_elapsed event, I am getting the datasource from thedatabase and binding it into the gridview. The problem is, theretrieved data from th database is not displaying in the gridview. Hereis my code,

Default.aspx:

<%@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>
<atlas:ScriptManager EnablePartialRendering="true" ID="UpdateManager" runat="server"></atlas:ScriptManager>
<form id="form1" runat="server">
<div>

<atlas:UpdatePanel ID="upCityPanel" runat="server" Mode="Conditional">
<ContentTemplate>
<asp:GridView ID="GrdCity" runat="server" PageSize="5"></asp:GridView>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="btn" EventName="Click" />
</Triggers>
</atlas:UpdatePanel>
<asp:Button runat="server" ID="btnReload" Text="Click to Reload" OnClick="ReloadGrid" />
</div>
</form>
</body>
</html
Default.aspx.cs:

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 System.Data.SqlClient;
using System.Timers;

public partial class _Default : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("server=localhost/;database=new;user id=sa;password=;");

protected void Page_Load(object sender, EventArgs e)
{
Timer timer = new Timer();
timer.Enabled = true;
timer.Interval = 5000;
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
}

void timer_Elapsed(object sender, ElapsedEventArgs e)
{
ReloadGrid(this, EventArgs.Empty);
}

protected void ReloadGrid(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select distinct(city) from authors", conn);
DataTable dt = new DataTable();
if (dt != null)
da.Fill(dt);
GrdCity.DataSource = dt;
GrdCity.DataBind();
}

}

Can anyone tell me what should I need to do? for getting the proper output.

Thanks in advance.

UdhayaOk, everything looks good but using a System.Timer, you need to use an AJax timer, just drag and drop from the toolbox INSIDE the UpdatePanel and everything is going to work great!
Thanks a lot Albert, it's working fine now. Thanks for your reply :-)

No worries, glad I can help.

Please make sure you mark my post as answered so other people having the same problem can find the solution.

problem of picture flashed on using Timer control

When I am using a timer control to updated the panel frequently, there is a problem as follow:

The picture which is in the Update Panel will flash and refresh when the timer ticked.

How can I reslove this problem?

I want that if the imagebox's imageurl isn't modified, the picture don't need to refresh.

When you use a Timer to trigger an UpdatePanel, the UpdatePanel's innerHTML is refreshed each tick even if there are no changes to it. If you want to only refresh the panel when there are changes, you might consider usingthis technique to poll the server for updates and only refresh the UpdatePanel if need be.