Showing posts with label update. Show all posts
Showing posts with label update. Show all posts

Wednesday, March 28, 2012

ASP.NET Ajax Timer

Greetings,

i want to implement ajax timer so it will update an updatepanel every five seconds based on a certain codition so i try the following:

<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
</asp:ScriptManager>

</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="UpdateTime">
</asp:Timer>

in the code behind i write the folowing:

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToLongTimeString();

}
protected void UpdateTime(object sender, EventArgs e)
{
if (new Random().Next(0, 4) == 1)
{
UpdatePanel1.Update();
}

}

so what i notice that every five seconds the tick event will happen and the updatepanel1 will be updated regardless of the condition that i implement it in the UpdateTime method ,what is logic since the tick event happens.

so how can i solve this problem??

your help is highly appreciated

best regards

I tested your codes in Visual Studio .Net 2005 with Ajax RC 1.0.Try to change some of your codes as the following and it should work fine.
<div>
<asp:UpdatePanel ID="upnlTimer" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTimer" runat="server" Text="Date Time"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
Wish the above can help you.

Thank you for the support

so what i add only the

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="UpdateTime"></asp:Timer>
</ContentTemplate>

</asp:UpdatePanel>
</div>

so when i place the timer control within the contenttemplate of the updatepanel so i dont need to put the timer control within the triggers of the updatepanel

so what i conclude that it will not work if i place the timer control outside the update panel.

asp.net ajax refresh the UpdatePanel every 30 sec?

I am currently using Timer control inside my update panel to update automatically every 30 sec. However i wanted to use json to do the same thing.

Any suggestions?

Thanks

Hi,

JSON (JavaScript Object Notation) is a lightweight data-interchange format, or it can be viewed as a protocal defining how object is serialized when transporting.

It can't be used to perform actions at a certain interval like Timer.

Please refer to this for more information:http://msdn2.microsoft.com/en-us/library/bb299886.aspx

Hope this helps.

Saturday, March 24, 2012

ASP.NET AJAX - Why IsPostBack=false?

I'm using ASP.NET AJAX. There is UpdatePanel on the page. It contains GridView. When I press "Edit", "Update" or "Cancel" button in the GridView then UpdatePanel reloads. Also executes code "if (!IsPostBack) { ... }" in Page_Load event on the server - but I don't need it!!! This code must run only once when page is loading for the first time (some time isPostBack=true, some time =false. But it must be =true everytime!),. This happens not every time when I click on EDIT / CANCEL but from time to time. I made some experiments and found the couse of such behavior. Here is the code:

Default.aspx

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Test Ajax + GridView</title></head><body> <form id="form1" runat="server"> <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" /> <asp:SqlDataSource ID="s1" runat="server" ConnectionString="...connectiong to Northwind..." SelectCommand="SELECT top 5 * FROM Categories" /> <div> <asp:UpdatePanel ID="update_lgota" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="grid_lgota" runat="server" AutoGenerateColumns="true" DataSourceID="s1"> <Columns> <asp:CommandField ButtonType="Image" ShowEditButton="True" EditImageUrl="~/images/btn_edit.gif" UpdateImageUrl="~/images/btn_update.gif" CancelImageUrl="~/images/btn_cancel.gif" /> </Columns> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> </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;public partialclass _Default : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e) {if (!IsPostBack) {string s ="FIRST"; } }}

Put Breakpoint (F9) into if (!isPostBack) { ... }. Then run project and press "EDIT" in the GridView. Some times (not everytime) this breakpoint will activates. So we get isPostBack=false during postback - this couse some logic mistakes on the page.

BUT If you delete a line:

ButtonType="Image"

from the Default.aspx file then everything begin to work correctly, isPostBack=true everytime! This is very strange, may be this is ERROR or BUG in VisualStudio OR maybe I do everything in the wrong way. Please explain me what's wrong in my code? Why isPostBack has incorrect value when I'm using ButtonType="Image"? Why IsPostBack=false on postback? (the same problem if I use IsAsynhPostBack and IsCallBack)

I have installed:
- Microsoft Visual Web Developer 2005 SP1
- ASP.NET 2.0 AJAX Extensions 1.0
- AjaxControlToolkit 1.0.10606.0

I think what you're looking for instead of(!IsPostBack) isIf (!ScriptManager.GetCurrent(Page).IsInAsyncPostBack).

http://www.asp.net/learn/ajax-videos/video-173.aspx



That is a bit odd. IsPostBack should definitely be true there.

You might consider changing that CommandField to a TemplateField to test. I have a GridView in an UpdatePanel that I just ran through the debugger to test, and its templated edit/update/cancel buttons do correctly cause Page.IsPostBack to be true during the partial postbacks they trigger.

For example, this is the command column in the grid I just tested:

<asp:TemplateField>
<ItemStyle Width="40px" HorizontalAlign="Center" />
<ItemTemplate>
<asp:ImageButton runat="server" ID="EditButton" CommandName="Edit" ImageUrl="~/Images/edit-wide.png" CausesValidation="false" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex")%>' OnCommand="EquipmentList_RowEditing" />
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton runat="server" ID="UpdateButton" CommandName="Update" ImageUrl="~/Images/ok.gif" CausesValidation="false" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex")%>' OnCommand="EquipmentList_RowUpdating" />
<asp:ImageButton runat="server" ID="CancelButton" CommandName="Cancel" ImageUrl="~/Images/cancel.gif" CausesValidation="false" CommandArgument='<%# DataBinder.Eval(Container, "RowIndex")%>' OnCommand="EquipmentList_CancelEditing" />
</EditItemTemplate>
</asp:TemplateField>

Thanks. It was useful

ASP.Net Ajax - Making UpdatePanel invisible while loading the gridview inside update panel

This is my first ASP.net Ajax program. I have a gridview inside the UpdatePanel and DropDownList outside. On theSelectedIndexChanged of the dropdown I am loading the Gridview. While the gridview is getting loaded, the UpdateProgress contraol is displayed. My problem, after the gridview is displayed, when I select a different item from dropdown control, the gridview is displayed with the data from the previous select until it gets refreshed with new data. As soon as I change the select from dropdown, I want the gridview within the updatepanel to be invisible, until the data gets loaded. Following is the code snippet:

ProtectedSub ddl_manufacturer_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles ddl_manufacturer.SelectedIndexChanged

lbl_ListHeader.Text =

"Manufacturer Price List For " & ddl_manufacturer.SelectedItem.Text

GrdView_manufPriceList.Visible =

False

UpdatePanel1.Visible =

False

LoadManufPriceList()

UpdatePanel1.Visible =

True

GrdView_manufPriceList.Visible =

True

EndSub

Thanks in advance.

bm!an,

I wanted the same effect and used the UpdatePanelAnimationExtender from the AJAX Control Toolkit (http://ajax.asp.net/ajaxtoolkit).

I simply set the OnUpdating animation to FadeOut and the OnUpdated animation to FadeIn. Worked like a charm.


Kalorm,

Thanks a lot. It worked.

ASP.NET AJAX - Events calendar

I have been searching far and wide for an example showing how to update events on
an events calendar using ASP.Net AJAX.

The only examples I find are commercial modules or not ASP.Net AJAX.

If anyone has had more luck than I can you point me to the resource.

Thanks

Bump... Is anyone out there?

ASP.Net AJAX - Cannot Set focus to a TextBox inside an Update Panel

Hi; I am using the released version of AJAX Controls and I am working on a Web Application with a Masterpage.
What I would like to do is, I have two Radiobuttons and two TextBoxes inside an update panel; When the user clicks the RadioButton1, I would like to set the focus to TextBox1 and if the user clicks the RadioButton2, I would like to set the focus to the TextBox2. I have googled for it and found couple of similar solutions that works with the beta AJAX assembly "Microsoft.Web.Atlas" but it doesn't work with the ASP.Net AJAX which I am using in my current project.

The following code works just fine when I use theMicrosoft.Web.Atlas soplease let me know if anyone knows a solution that works with the released version of AJAX Controls; Thanks in advance.

//***************************************************************************************

//Code behindprotected void RadioButton1_CheckedChanged(object sender, EventArgs e) { SetMyFocus(ref TextBox1); TextBox1.Focus(); }private void SetMyFocus(ref TextBox txtBox) {string focusString ="setTimeout(\"$('" + txtBox.ClientID + "').focus(); \", 100);"; ClientScript.RegisterStartupScript(this.GetType(),"focusString", focusString,true); }protected void RadioButton2_CheckedChanged(object sender, EventArgs e) { SetMyFocus(ref TextBox2); TextBox2.Focus(); }

//***************************************************************************************
 The following code is from the source view of the page
 
<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/Test.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" Title="Untitled Page" %><%@dotnet.itags.org. Register Assembly="Microsoft.Web.Atlas" Namespace="Microsoft.Web.UI" TagPrefix="cc1" %><asp:Content ID="Content1" ContentPlaceHolderID="CPHTest" Runat="Server"> <cc1:ScriptManager ID="ScriptManager2" runat="server" EnablePartialRendering="true"> </cc1:ScriptManager> <cc1:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True" OnCheckedChanged="RadioButton1_CheckedChanged" GroupName="Group1" /><br /> <asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True" GroupName="Group1" OnCheckedChanged="RadioButton2_CheckedChanged" /><br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />   </ContentTemplate> </cc1:UpdatePanel></asp:Content>

Hi,

I am using the new SetFocus method of the ScriptManager class.

Example:

ScriptManager1.SetFocus(TextBox2);

I works with the last release of Microsoft AJAX.

Hope this helps,

David


Wow; that works great; Thanks for the quick reply.

Jacob


I am using the Atlas beta version. I am having the same textbox focus problem. I tried to use the setFocus(), but i couldnt find the setFocus() of the scriptmanager.

Where to use

ScriptManager1.SetFocus(TextBox2);

I just have the

ScriptManager1.Focus() method. please help.

Thanks in Advance


Use the latest version of ASP.NET AJAX


Thanks lot

I also having same prob and search the web for solution. This is tha only place that I found a resolution.

Thanks lot again

ASP.NET 2.0 Wizard in Update Panel BUG

Hi all,

I have a Wizard control within an Update Panel. This used to work fine in Atlas but now that I upgraded to the ASP.NET Ajax release, I've discovered a bug.

When you go through the wizard, clicking the next button to go from step 1 to step 2 works fine. When you click the next button to go from step 2 to step 3, nothing happens and there is a javascript error -'null' is null or not an object. This same bug occurs under the same scenario in a MultiView, even if the next buttons are outside of the MultiView.

This seems to have something to do with ajax choking on the ASP.NET client-side validation, as you can set CausesValidation="false" on the next buttons and then you can go on to step 3. However, this isn't much of a solution, as I want to have client-side validation and not just the Page.Validate() / if(Page.IsValid) server-side code.

Anyone know a way around this bug or if it is being fixed in an upcoming release?

Thanks,

Justin

It appears it had nothing to do with the wizard and everything to do with the asp.net validator controls not working correctly in the current release of asp.net ajax 1.0.

The answer until they fix this is:

http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx

ASP.Net 2.0 - Page Trace and Update Panel

I am just getting started with AJAX.

I have a .Net 2.0 application with page/debug trace set to true. I have a simple page listed below. When I click the button with the page/debug trace set to true, I get an error message basically saying that trace has to be false.

Does this mean that I have to always have the page/debug trace set to true for the AJAX to work?

<asp:LabelID="Label1"runat="server"Text="Label"Width="249px"></asp:Label><br/>

<br/>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<hr/>

<asp:LabelID="Label2"runat="server"Text="Label"Width="249px"></asp:Label>

<hr/>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="Button1"EventName="Click"/>

</Triggers>

</asp:UpdatePanel>

<br/>

<asp:LabelID="Label3"runat="server"Text="Label"Width="249px"></asp:Label><br/>

<br/>

<asp:ButtonID="Button1"runat="server"Text="Button"Width="233px"/></div>

Actually, I mean does page/debug trace always have to be set to FALSE for me to be able to use AJAX?

Hi,

Yes, you can't enable trace on page for asynchronous request. That's because the response must conform to a specified format, otherwise, it will fail.


Tracing doesn't work in the UpdatePanel, it'sbasically equal to using Response.Write which is also a no-no.

-Damien

Wednesday, March 21, 2012

asp controls unknown inside updatepanel in nested master

I have a master page with scriptmanager and update panel outside the contentplaceholder. Immediately the updatepanel and all nested master and non-master pages show all asp elements as unknown. If I move the update panel to inside the nested master content element it is still unknown as is all of the nested elements and pages.

I am running the december releases. I have un-installed and re-installed a couple of times. This is always the behavior. The code runs, but there is not intellisense and virtually everything is marked with the red underlines, and the error page is full (but doesn't stop the app coming up).

I looked at a number of posts suggesting rebuilding the toolbox. Nothing seems to help. However, the ajax toolkit controls are recognized because there is an @dotnet.itags.org.Register in the nested master.

Additionally, despite the post I found saying it had been fixed, I must keep my master pages open or none of the controls on any of the lower pages are recognized.

Anyone know of a post I missed about this issue?

/bump

I have the same issue.

In visual studio i create a new Ajax enabled website. I create a master page and a content page. The content page is to contain an update panel with some stuff in it. The AjaxControlToolkit is recognized while the Update Panel is not.

Cheers,

Michael


I'm also having this same problem. I have a Master page and my update panel is in the content page. AjaxControlToolkit controls are recognized but any controls within the update panel are not.
I'm also having this same problem. I have a Master page and my update panel is in the content page. AjaxControlToolkit controls are recognized but any controls within the update panel are not.

bump

I have 2 update panels (master/detail) that I am wiring together.

I am trying to make an object data source in UP2 use a praramater from a gridview in UP1. On creation of the data source, the Master gridview is not visible, but I hard coded it, and it actually works fine.

I think this is a bug in the UI of VS 2005.


Make sure you have the content inside your update panel wrapped with <ContentTemplate></ContentTemplate>

ASP components inside UpdatePanel been red underlined

I'd like if anyone has experienced the same issue than me.
Since I updated to Ajax Beta 1, each object or components that I placed inside an update panel aren't recognized, all are red underlined, and which is more annoying, and even if I'mm being able to complete the compilation and run the application, a lot of errors messages are being throwed (for example: Error 31 Element 'RadioButtonList' is not a known element. This can occur if there is a compilation error in the Web site) and it makes a little bit difficult to find errors during debugging.

I suppose I had missed a step during the upgrading, because I have not heard about other people with the same issue.

Any hint/suggestion to put me on the right way the solve this is welcome!!!

Thanks,

Scott Gu has a Gotcha on this. See his blog for the explanation.

ashx image not updating in UpdatePanel

Hi there


I have an update panel containing an image. The image source is pointing to a .ashx file..

<asp:UpdatePanel ID="GraphUpdatePanel" runat="server" UpdateMode="always">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GraphUpdateTimer" EventName="Tick" />
</Triggers>

<ContentTemplate>
<div>
<img alt="graph" style="width: 120px; height: 100px" id="imgGraph" runat="server" src="http://pics.10026.com/?src=VUMeter.ashx" />
</div>

</ContentTemplate>
</asp:UpdatePanel>

I also have a tick function outside of the update panel

<asp:Timer ID="GraphUpdateTimer" Interval="1000" runat="server" Enabled="true" OnTick="GraphUpdateTimer_Tick">
</asp:Timer

My GraphUpdateTimer tick event changes the src attribute of the iimage to include some query strings, e.g.

imgGraph.Src = "VUMeter.ashx?x=1&y=2";

The tick event is hit every second as I would expect but the ProcessRequest in the .ashx file is not hit...!?!?!?

Any ideas why?

Please help (it's doing my nut!!!!)

Thanks

Mike

Hi

I can see nothing wrong with that code, try installing fiddlerhttp://www.fiddlertool.com/fiddler/ to see if the request is being sent to the VUMeter.ashx file after the tick event. Is the graph being written out correctly on first load of the page?

Cheers Si


Hi

Upon the 1st page load I can see the ashx call, but following that initial call, all I see are the main pages, and no more ashx entries...

POST http://192.168.202.141/AudioSoft/Maintenance/NotImplemented.aspx?AppName=Maintenance
200 OK

GET http://192.168.202.141/AudioSoft/Maintenance/VUMeter.ashx?recorder=RADARSCREEN&channel=-1
200 OK

POST http://192.168.202.141/AudioSoft/Maintenance/NotImplemented.aspx?AppName=Maintenance
200 OK

POST http://192.168.202.141/AudioSoft/Maintenance/NotImplemented.aspx?AppName=Maintenance
200 OK

POST http://192.168.202.141/AudioSoft/Maintenance/NotImplemented.aspx?AppName=Maintenance
200 OK

POST http://192.168.202.141/AudioSoft/Maintenance/NotImplemented.aspx?AppName=Maintenance
200 OK

POST http://192.168.202.141/AudioSoft/Maintenance/NotImplemented.aspx?AppName=Maintenance
200 OK

POST http://192.168.202.141/AudioSoft/Maintenance/NotImplemented.aspx?AppName=Maintenance
200 OK

POST http://192.168.202.141/AudioSoft/Maintenance/NotImplemented.aspx?AppName=Maintenance
200 OK

(NotImplemented.aspx is my page name and the ashx file is called/set from there)

Mike


Ok, this could be a browser caching issue, did you say your definatley changing the querystring everytime? if not it could be the browser checking the cache, seeing it's got the image file already in the cache(as it's got the same url), so does not need to load it. I'd look at setting the content-expiry on the ashx file. Check here(you may need to modify this slightly)

http://www.gloo.ru/gloom.another_asp_net_hack_static_image_cache._l_en.wiki.aspx

Cheers Si


Hi

It does look like this was the problem.

I solved it by just tagging DateTime.Now to the query string so that it was different each time.


All works now!

Many thanks

Mike