Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Wednesday, March 28, 2012

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

Monday, March 26, 2012

Access control on MasterPage from within content page

Hi all,

I have a MasterPage with invisible Label.

In content page I have a few controls and any Button.

When user clicks the Button, the Label on MasterPage appears.

So far - so good.

If I use an UpdatePanel inside the content page, the Label stay invisibleSad.

I know, that it's right behavior for Ajax enabled application, but...

What is the solution?

MasterPage:

<%@dotnet.itags.org. Master Language="C#" AutoEventWireup="true" CodeFile="TestMasterPage.master.cs" Inherits="TestMasterPage" %><!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:contentplaceholder id="ContentPlaceHolder1" runat="server"> </asp:contentplaceholder> <asp:Label ID="Label1" runat="server" Text="Error!" Visible="False"/> </form></body></html>

Content page:

<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/TestMasterPage.master" AutoEventWireup="true" CodeFile="TestContentPage.aspx.cs" Inherits="TestContentPage" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:ListBox ID="ListBox1" runat="server"> <asp:ListItem Value="1">Item 1</asp:ListItem> <asp:ListItem Value="2">Item 2</asp:ListItem> <asp:ListItem Value="3">Item 3</asp:ListItem> <asp:ListItem Value="4">Item 4</asp:ListItem> </asp:ListBox> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </ContentTemplate> </asp:UpdatePanel></asp:Content>

Content page code behind:

protected void Button1_Click(object sender, EventArgs e) {//Do something... //... Label lbl = (Label)Page.Master.FindControl("Label1");if (lbl !=null) lbl.Visible =true; }

The solution: enclose the Label on the MasterPage by UpdatePanel:

<%@. Master Language="C#" AutoEventWireup="true" CodeFile="TestMasterPage.master.cs" Inherits="TestMasterPage" %><!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:contentplaceholder id="ContentPlaceHolder1" runat="server"/> <asp:UpdatePanel ID="updatePanel2" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Error!" Visible="False"/> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

Saturday, March 24, 2012

About Sys.WebForms.PageRequestManagerParserErrorException error

Hello everybody,

My ajax powered web site throws an error when pressing a button or linkbutton inside an UpdatePanel.

I've searched for a solution. All of the blogposts, solutions etc is about the "common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled." suggestion written in the error text itself.

But in my scenario, only IE6 (and may be below) users see this error. I am using IE7, and my site works like a charm. (all my friends using IE7 doesn't have problems with the site)

I've searched my code for response.write stuff but there isn't any. I've removed some custom controls (msn like popup win, flash container controls etc.) but it's the same with IE6 users. The error is :

--------
Microsoft Internet Explorer
--------
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Details: Error parsing near 'eTitle||Favorilerim|

0

'.
--------
Tamam (OK)
--------

Anybody have suggestions?

Hi bsarica,

Maybe this article is useful for you:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312496

Regards,


I forgot to mention smthng.

It is not working on firefox too.


Any other suggestions? :(


I had a very similar error when I encountered code where the asynchronous call back was making a call to Server.Transfer(). I'm not sure whether or not this helps you or not, but doing a Server.Redirect() fixed the problem for me.

about Atlas

Hello:

I'm new in Atlas, and I need help to understand :)

My scenario is that I have one gridview (vsnet 2005) and a button. When I click button, I call remote web service (http:outerIP/myservice.asmx) that returns data used for gridview's datasource.

I have seen examples for calling from javascript to web service, but I don't understand proccess.

1- I add the web reference to my vs2005 (with atlas template) project.

2- I modify this code that template created in aspx.

<asp:ScriptManagerrunat="server"ID="scriptManagerId"><Scripts><asp:ScriptReferencePath="CallWebServiceMethods.js"/><-----</Scripts><Services><asp:ServiceReferencePath="http://OUTERIP/webservices/MyService.asmx"InlineScript="false"/></Services></asp:ScriptManager>

my ask are:

    this .js file "CallWebServiceMethods.js"... how is generated? is it a copy of real web service?Must I make this .js?Is not intelllisense in javascript for calling webservice methods?If i call webservice method from client side in javascript... how can I to send to grid this received datasource?

Thanks a lot and regards!

For your four questions, I'd like to share my ideas with you for reference.
1.The Services collection allows you to wire up web services that can be consumed via client side script. The ScriptManager will generate proxy JavaScript scripts that allow the developer to use similar syntax on the client as is used on the server. The supported bits will not support calls to Windows Communication Foundation (WCF) services, however, this functionality will be added to the non-supported CTP builds in the future.
The AJAX Extension includes an HttpHandler that is used to generate the proxy scripts and handle JSON serialization called Microsoft.Web.Script.Services.ScriptHandlerFactory. Internally the HttpHandler routes .asmx calls that require JSON serialization to the AJAX networking stack.Calls to .asmx that don't use the special syntax (http://.../foo.asmx/js/methodname) are routed to the original ASP.NET 2.0 .asmx handler. Note that this means if a developer created a custom .asmx handler, when AJAX web services are enabled on a site the ScriptHandlerFactory will instead always fall back to System.Web.Services.Protocols.WebServiceHandlerFactory. There is no capability to chain the AJAX handler to a custom .asmx handler.
You wire up the web services to the <ScriptManager> by adding a ServiceReference to the Script Manager. The following demonstrates how to add a service reference to foo.asmx. You can also do this by accessing the Services collection in the Property pane of the IDE.
<asp:ScriptManager runat="server" ID="scriptManager">
<Services>
<asp:ServiceReference Path="~/.../foo.asmx" />
</Services>
</asp:ScriptManager
This will result in javascript objects being instantiated in the browser which are proxy objects for corresponding .NET classes in foo.asmx. The proxy objects are used
a)To make asynchronous requests in JavaScript to the asmx web methods
b)To create and initialize instances of proxies of server data types. This allows developers to pass complex objects as parameters as well as handling complex objects in the response.

ServiceReference Properties
You add a ServiceReference control to the <Services> section for each web service you need to access via JavaScript. The reference drives the process of requesting the proxy script on the client. The proxy script is covered later in this lesson. The ServiceReference control has two properties: InlineScript and Path.
InlineScript - The InlineScript attribute on the ServiceReference tag determines whether the script for generating the Javascript proxies is included within the page, or is downloaded as a separate script resource. The default value is false.

<asp:ServiceReference Path="~/.../foo.asmx" InlineScript="true" /
When InlineScript is set to false (or is absent) then the proxy generation script is obtained by a separate request to http://.../foo.asmx/js which is handled by the AJAX HttpHandler. Since the script can be cached in the browser, this option is preferable when multiple asmx pages use the same service reference.

When InlineScript is set to true the proxy generation script is included as an inline script block within the page. This can improve performance by reducing the number of network requests, particularly if there are many service references within the page and other pages do not reference the same services.

Path: The Path property specifies the URL for accessing the web service. The ServiceReference tag can only be used for local services (i.e. services within the same domain). Local services can be addressed by a relative, app-relative, domain-relative or absolute path. For domain-relative or absolute paths it is up to the developer to ensure that the path does correspond to the same domain, and so will actually work. The proxy generation code will initialize the path property to the corresponding domain-relative path.

This means that if you enter have the following:
<asp:ServiceReference InlineScript="true" Path="http://mydomain.com/Parts.asmx" /
The proxy script will be requested using the full URL:
http://mydomain.com/Parts.asmx/js

However the path in the proxy script will call the webservice using the virtual path of /Parts.asmx.

If you specify InLineScript="true", you have to either use a virtual or relative path. You can also use the ~/ syntax to have ASP.NET build the app relative path for you. You will get the following error message if InLineScript="true" and the Path is pointing to a different domain than the ASPX page was requested from:

The path "http://test.com/TestServices/WebService.asmx" is not supported. When InlineScript=true, the path should be a relative path pointing to the same web application as the current page.

Path to external services
For external use of services, using a ServiceReference with an absolute URL will fail, as specified above. It is recommend that developers do the following:
?Download the script, using http://mydomain.com/Parts.asmx/js
?Open the .js file and set the correct value of the path property. If the web service class is called "WebService" and the site is http://test.com, you would do the following:

Change: WebService.set_path("/TestServices/WebService.asmx");
To: WebService.set_path("http://test.com/TestServices/WebService.asmx");

?Reference the script in the <ScriptManager>
<asp:ScriptManager ID="MyManager" runat="server">
<Scripts>
<asp:ScriptReference Path="WebServiceDifferentURL.js" />
</Scripts>
</asp:ScriptManager
If you choose to do this, users will get the following message when they click the button letting the user know that they are sending a request to a different site:

Simple Demo
Proxy generation script
When the service request tag does not specify InlineScript = "true", a separate HTTP request is made to the asmx to download the proxy script. This is done using a special URL request syntax as mentioned previously.

http://.../foo.asmx/js

This request returns the proxy generation scripts that instantiate the specific JavaScript proxy objects for foo.asmx. This is done to allow developers to write JavaScript code using namespaces and classes which are not inherently available in JavaScript. This also abstracts the serialization of complex types from the developer. The content type of the returned proxy script is set to "application/x-javascript".

Proxy objects graph corresponding to namespace
The proxy generation script will create a Web Service proxy object corresponding to any Web Service class in foo.asmx that has a server attribute [ScriptService] and contains one or more methods marked with the [WebMethod] attribute.

[Microsoft.Web.Script.Services.ScriptService]
public class PeopleServices : System.Web.Services.WebService {
}
2.No.This is not necessary to call a web service through javascript,which only provides a method to consume web service from the client side.You can call a web service method according to the traditional way.
3.There are a lot of Ajax controls which can consume web service and have ServicePath and Servicemethod properties to specify a web service.This is intellisense.But it is not .js file.
4.Calling Web Services in JavaScript
Now that we've talked about setting up the ScriptManager and how the proxy functionality works, let's take a look at how developers will leverage this technology. We'll look at passing both simple and complex data type and handling errors. During the demos, we'll take a look at the network traffic being passed to and from the server.

"Fire and Forget" Invocation
If the web service class on the server includes a web method that does not return data, you can call the web service without having to handle a response. This is the simplest web method call that can be made from the client. For example, your application has the following web method:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[Microsoft.Web.Script.Services.ScriptService]
public class Parts : System.Web.Services.WebService
{
[WebMethod]
public void NoReturn()
{
//do work here
System.Threading.Thread.Sleep(2000);
}
}

The following JavaScript can be used to invoke that web method

function RunWebService()
{
Parts.NoReturn();
}

If the webservice is in a custom namespace, you would need to fully
qualify the call to the webservice. For example, if the WebService
has a namespace of MyCustomNameSpace.WebServices, the above JavaScript
becomes:

function RunWebService()
{
MyCustomNameSpace.WebServices.Parts.NoReturn();
}

If you want to get the dataset which is returned by?a?web?service,you?can?call?it?according?to?the?traditional?way?and?bind?it?to?asp:GridView.
If?you?would?like?to?consume?some?web?service?methods?through?javascript?from?the?client?side,try?to?use?Ajax?control?toolkit?which?are?useful?for?you.?

Wish the above can help you.

great answer. thanks and regards!

A simples scenario using GridView + Buttons + TextBoxes

Hello!

I have a GridView and some TextBoxes to type the data (Id, Name...). I also have a button called "_btnSave". I want to add new itens to my DataSource when I click on the Save button... to do this, I've used two updatePanels: one to GridView and other to the button.

The Button UpdatePanel is used just to avoido the Button Postback...

I'd like to know if there is any way to use just the UpdatePanel of the grid. Is it possible?

Thanks

hello.

if i understood your question correctly, then i'd say that you can put everything inside an update panel...it shuold work that way...

A Simple Atlas Work,but Still have Unknown Error BUG

Simply, i Place a Textbox and a button,when i click the button, it response.write(textbox1.text)
but, when i click the button, it show a java script pop-up and show me Unknown error..

below is the code:

1Default.aspx2<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="true" ValidateRequest="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>34<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">5<html xmlns="http://www.w3.org/1999/xhtml">6<head runat="server">7 <title>ASPNET_Atlas_Testing</title>8</head>9<body>10<form id="form1" runat="server">11<div>12 <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True"/>13<!-- This section of the page is wrapped by an UpdatePanel. -->14 <atlas:updatepanel id="up" runat="server" mode="Conditional" rendermode="Inline">15 <triggers>16 <atlas:controleventtrigger controlid="TextBox1" eventname="TextChanged" />17 </triggers>18 <contenttemplate>19 <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox><br/>20 </contenttemplate>21 </atlas:updatepanel>2223<!-- This section is also wrapped by an UpdatePanel. -->24 <atlas:updatepanel runat="server" id="up1" mode="Conditional" rendermode="Inline">25 <triggers>26 <atlas:controleventtrigger controlid="Button1" eventname="Click" />27 </triggers>28 <contenttemplate>29 <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>30 </contenttemplate>31 </atlas:updatepanel>32</div>33</form>34</body>35</html>3637
1Default.vb23PartialClass _Default4Inherits System.Web.UI.Page56Protected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Button1.Click7 Response.Write(TextBox1.Text)8End Sub910 Protected Sub TextBox1_TextChanged(ByVal senderAs Object,ByVal eAs System.EventArgs)11 Response.Write(TextBox1.Text)12End Sub13End Class1415
Check to make sure your web.config file is setup right and that your dll is in place (/bin) and not corrupt, as I'm not getting a javascript error when I try your code. It also doesn't work as you wrote it, though, and so I tried adding a label to one of the update panels and having the button change its value based on the text prop of the textbox1, and that worked fine. So I suspect that with update panels (this is just a guess) that you can't use Response.Write; whcih would make sense if you conceive of the Response object as passing a whole page rather than just the partial page the update panel is looking for.

Hi,

Remove all response.write statements & replace them with this.page.registerclientscriptblock(script);

Amit Lohogaonkar

mcp,mcad

lohogaonkaramit@.yahoo.com

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

90 seconds delay for posting back to the server when user clicks the abortButton

Hi,

In my application, I have an UpdateProgress control with an abortButton. I hook the Onclick attribute of this button to a server-side method.

When the application does not contain a global.asax file, all is working perfectly: When the user click on the abortButton, it posts back immediately.

But, when the application contains a global.asax file, there is a delay of approximatively 90 seconds between the user's click of the abortButton and the execution of the method in the server-side.

Here's a little exemple how to reproduce the problem:

aspx page:

<%

@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>
<%@dotnet.itags.org.RegisterAssembly="Microsoft.Web.Atlas"Namespace="Microsoft.Web.UI"TagPrefix="cc1" %>
<!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"><headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<cc1:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="True">
</cc1:ScriptManager>
</div>
<cc1:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/>
<asp:LabelID="lblResultat"runat="server"Text="Label"></asp:Label>
</ContentTemplate>
</cc1:UpdatePanel>
<cc1:UpdateProgressID="UpdateProgress1"runat="server">
<ProgressTemplate>
Contacting server... <br/><br/>
<asp:buttonid="abortButton"runat="server"OnClick="abortButton_ServerClick"Text="Abort Request"/>
</ProgressTemplate>
</cc1:UpdateProgress>
</form>
</body>

Code behind:

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.Threading;
using System.ComponentModel;
using System.Net;

public

partialclass_Default : System.Web.UI.Page
{
privateEventWaitHandle ewhWait =newEventWaitHandle(false,EventResetMode.ManualReset);

protectedvoid Page_Load(object sender,EventArgs e)
{
}

protectedvoid Button1_Click(object sender,EventArgs e)
{
Thread thread =newThread(newThreadStart(ThreadLong));
thread.Start();
ewhWait.WaitOne();
lblResultat.Text ="End of lengthy method";
}

publicvoid ThreadLong()
{
Thread.Sleep(100000);
ewhWait.Set();
}

protectedvoid abortButton_ServerClick(object sender,EventArgs e)
{
ewhWait.Set();
}
}

Global.asax

<%

@dotnet.itags.org.ApplicationLanguage="C#" %>
<scriptrunat="server">
void Application_Start(object sender,EventArgs e)
{
// Code that runs on application startup
}void Application_End(object sender,EventArgs e)
{
// Code that runs on application shutdown
}void Application_Error(object sender,EventArgs e)
{
// Code that runs when an unhandled error occurs
}void Session_Start(object sender,EventArgs e)
{
// Code that runs when a new session is started
}void Session_End(object sender,EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>

To Reproduce the problem:

1- put a breakpoint in theabortButton_ServerClick method
2- Execute the application and clickButton1
3- clickAbort Request
4- after 90 seconds, the application breaks.
5- Remove Global.asax from the solution
6- Execute the application and clickButton1
7- clickAbort Request
8- the application breaks immediately.

This delay appends also under different conditions; I explained the Global.asax case because it is the easiest to reproduce.

Is there someone knowing the reason of this behavior?

How can I force a postback of the abortButton ?

Thank you for any input .

Well it looks like you have gone to quite a bit of trouble just to get an abortButton cancel the current requests. I hate to tell you but there is a much easier way to abort requests. Atlas has a special button called abortButton (go figure). So basically the atlas framework looks for a button event with the id of abortButton. You don't have to create some custom method to cancel the request the atlas framework handles it, and it works great. Below is all you have to put into the UpdateProgress template and you will be set. At least now you have some really cool code to shutdown events :). By the way when you press the button it doesn't force a postback it just ends the request.

<

inputid="abortButton"type="button"runat="server"value="Stop"/
Have fun!

JoeWeb


Hi JoeWeb.

Thanks for your quick reply.

I am using the Atlas abortButton.
I don't think it's matter if it is a "input type=button" or a asp:button, both are translate by Atlas like this :

<button id="UpdateProgress1_abortButton">
<click>
<invokeMethod target="_PageRequestManager" method="abortPostBack" />
</click>
</button>

But just to be sure, I try this button

<input id="abortButton" runat="server" type="button" value="Stop" onclick="AbortRequest()" />

and in the javascript AbortRequest() I call the server via anICallbackEventHandler method.

Atlas is doing a great job cancelling the request on the client side. The problem is that it does not cancel it on the server-side, the methode is still running.
You can verify that by placing a breakpoint in a long request. Even if you cancel it, the breakpoint will eventually be hit.

In my application, if somebody cancel the request I have some cleanup to do. So, if somebody cancels with the abortButton, the server must be inform in some way.

I also notice that if you cancel a request and re-submit it immediately, Atlas waits 90 seconds before posting it to the server.


Don't know what to tell you then. The application we have using atlas handles about 15 million records in a database for tons and tons of customers and it handles requests just fine. Haven't had any problems with it taking longer to send a request right after aborting it. We serve alot of data back and forth and it handles the request no problem. Sorry, don't know what to tell you.

Good luck.

JoeWeb


I finally pin-pointed the problem with the Atlas abort button.

I was wrong when I said that there was no request to the server when the Abort Button is clicked.
I traced Global.asax and I found out that the BeginRequest event is triggered.

The problem is with the creation of the handler between the ResolveRequestCache event and the AcquireRequestState event; this operation takes almost two minutes to complete.

I don't know why it tooks so long. For other request than the Abort Button it's very fast.

Am I the only one to have this problem ?