Showing posts with label create. Show all posts
Showing posts with label create. Show all posts

Wednesday, March 28, 2012

ASP.NET Ajax Progress Bar Revisited

I'm trying to create a Progress Bar that keeps track of a long running server-side process. I'm attempting to do this by having a primary ajax request start the server-side process, then having another polling function occassionally call back to the server via ajax to return the status if the server-side process started with the first ajax call. The problem is that the second ajax call doesn't return until the first one is completed.

Consider the following client-side code:

PageMethods.Execute(ExecuteCallback);

intervalId = window.setInterval(ExecuteStatus, 1000);
var done = false;

function ExecuteStatus()
{
PageMethods.ExecuteStatus(ExecuteStatusCallback);
}

function ExecuteStatusCallback( status )
{
<update progress bar>
if( !done )
window.setInterval( ExecuteStatus, 1000 );
}

function ExecuteCallback()
{
done = true;
}

PageMethods.Execute() is a server side process that can take a considerable amount of time. As it executes, it is setting a Session variable which indicates the status and completion percent of the process.

PageMethods.GetStatus() is a simple server side function which reads the aformentioned Session variable, and returns the status to the client.

The problem is that PageMethods.GetStatus() doesn't return until PageMethods.Execute() has completed and called back to the client.

Any ideas how to make this work?

Thanks much,

- Stew

I think you mean setTimeout instead of setInterval. Here's a working example. I hope this helps!

<%@. Page Language="C#" %><%@. Import Namespace="System.Web.Services" %><%@. Import Namespace="System.Threading" %><script runat="server"> [WebMethod] public static void Execute() { Thread.Sleep(5000); } [WebMethod] public static string ExecuteStatus() { return "."; }</script><!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="sm" runat="server" /> <input type="button" value="Execute" onclick="DoExecute(); return false;" /> <span id="status">Ready.</span> </form></body><script type="text/javascript"> var done = false; function ExecuteStatus() { PageMethods.ExecuteStatus(function (result) { if (done) { $get('status').innerHTML = "Done!"; } else { $get('status').innerHTML += result; window.setTimeout(ExecuteStatus, 1000); } }); } function DoExecute() { done = false; PageMethods.Execute(function () { done = true; }); $get('status').innerHTML = 'Executing'; window.setTimeout(ExecuteStatus, 1000); }</script></html>

Steve, thanks for the response. Yes I did use setTimeout; I made a mistake when I typed the message above. I'm not sure why your test would work and not mine, but I'll take a look when I get home on Monday.

Thanks again

- Stew


Steve,

Try setting a session variable in your test before executing the test. This is what appears to be causing the problem.

- Stew

ASP.Net AJAX Enabled Web Application template missing

I have installed ASP.NET2.0 AJAX Extensions 1.0 but I cannot find a template for the above when I try to create a new project and I believe there is one available from another post? If I try a new website, I get the AJAX enabled web site template, but what I really need is the web application template.

Anyone have any ideas as to why it is not appearing? Or what settings do I need to migrate from a ajax enabled website to a web application project to enable ajax?

Thanks in advance

Hi,

Thank you for your post!

As far as I know, there is none web application project template and AJAX web application project template in Visual Studio 2005/2008.

And we can take a website as a web application project.

If you really need a solution for a web site, you can add an empty solution, then add website to it,and other related project(e.g. class library project).

If you have further questions, let me know.

Best Regards,

Monday, March 26, 2012

ASP.NET AJAX Breaks with Custom Url Rewriting

I am having two related issues with ASP.NET AJAX. I used the AtlasToolkit PopupControlExtender to create a very simple Popup Calendar. I have created a custom HtmlTextWriter and HttpModule to rewrite incoming url's based on incoming path. So essiently if I nav /This/Page/Does/Not/Exist.aspx, the module will check the file system to see if that page physically exists, and if not then check the database for the corresponding PageId and rewrite it ~/Page.aspx?PageId=DoesNotExistId. Then I have overriden Render and written a custom HtmlTextWriter that looks for <form action=""> and sets that attribute equal to the fully qualified url requested.

The problem goes like this. Anytime before I do any ASP.NET UI events, everything is fine. After an ASP.NET AJAX UI event the Form.Action attribute reads Page.aspx?pageid=blah. Is there anyway to override this behavior?

Thank you,

Jason Lind

I'm like 99% sure this a bug. The line of js that causes this most of the time will do nothing, except when you're rewriting and then it breaks your application

See lines 1061 through 1069 in MicrosoftAjaxWebForms.js (the debug version) pasted here for your convienance:

if (handler) { handler(this,this._getPageLoadingEventArgs()); }if (formActionNode) {this._form.action = formActionNode.content;this._form._initialAction =this._form.action; }

Basically on any ASP.NET AJAX ui event the form.action is being reset to the response. I can see no reason for doing this, for as far as I can tell there is no information being added to the action. My guess is at some version in development this was the case and that approach was later dropped and this code never was refactored.

Can someone on the ASP.NET AJAX team please confirm this and assure me that in some later release this won't be an issue, maybe even commentif (formActionNode) {this._form.action = formActionNode.content;this._form._initialAction =this._form.action; } out and issue me a hot fix?

Thank you,

Jason Lind

Lead Software Engineer / Triton Tek


<script type="text/javascript">
Type.registerNamespace("ScriptLibrary");
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(pageLoaded);
function pageLoaded(sender, args) {
document.forms[0].action = requestUrl;
document.forms[0]._initialAction = requestUrl;
}
var requestUrl = "";
function body_onload()
{
requestUrl = document.forms[0].action;
}
</script>

Still should be fixed.


Kinda hard to say what's going on here, but first here's why we do that form action stuff. When modules such as session and authentication rewrite the URL in their cookieless modes, we need to reset the form action to be whatever the rewritten URL is. We do it in a manner similar to what you're doing by checking the form's action and grabbing whatever it has.

However, in your case it sounds like you're using a customwriter to do the work, which might be the problem in this scenario. Instead you should override the form's rendering functionality and just change the action there. Then Atlas will pick it up and use whatever you set. Here are a couple of articles on the subject:

General URL rewriting:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asp (but, ignore the part where it says to write an actionless URL!)
Atlas URL rewriting:http://geekswithblogs.net/lazydeveloper/archive/2006/08/17/88247.aspx (this is the important part)

Thanks,

Eilon

ASP.NET Ajax beginner question

Hi all,
I followed first walk through sample from
http://ajax.asp.net/docs/tutorials/IntroductionUpdatePanel.aspx to create my first testing page, The problem is after I clicked that botton, it still trigged a postback. Do I miss something?

Following is my code:

ASPX Page

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<%@dotnet.itags.org. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %
<!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">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Parcel created"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html
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;

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

}

protected void Button1_Click(object sender, EventArgs e) {
Label1.Text = "Refreshed at " + DateTime.Now.ToString();
}
}

Html code generated by page

<!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><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwULLTEyNTU5OTE4NDBkZFFbG+xINimfJjnJzMPyN5/bdPcr" />
</div
<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script
<script
src="http://forums.asp.net/AjaxSandbox/WebResource.axd?d=uPSIJPV09GNZkXa1aWLuZA2&t=632961560341637622" type="text/javascript"></script
<script
src="http://forums.asp.net/AjaxSandbox/ScriptResource.axd?d=Rdf9isNeXMPi-qNzO-XVRmXNOH0DmLQG-4RxW5WORPfrZ2K0YD5Icg_Bz9c5f0-wuytwMMng0hZa1k1SSKrW5yqEjrhREy__cV5gKfSghPU1&t=633053156500271737" type="text/javascript"></script>
<script
src="http://forums.asp.net/AjaxSandbox/ScriptResource.axd?d=Rdf9isNeXMPi-qNzO-XVRmXNOH0DmLQG-4RxW5WORPfrZ2K0YD5Icg_Bz9c5f0-wuytwMMng0hZa1k1SSKrW572e2ypQhyGf_JtyUNuUy11_drtp-tXJrGLYVAgwBUoK0&t=633053156500271737" type="text/javascript"></script>
<div>
<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ScriptManager1',
document.getElementById('form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1'], [], [], 90);
//]]>
</script
<div id="UpdatePanel1"
<span id="Label1">Parcel created</span>
<input type="submit" name="Button1" value="Button" id="Button1" /
</div>
</div>

<div
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"
value="/wEWAgLk5+S6DwKM54rGBofhZslYBM4FNpmEHJadJ6r8Aq3Z" />
</div
<script type="text/javascript">
<!--
Sys.Application.initialize();
// -->
</script>
</form>
</body>
</html>

Hey,

For your script manager, add EnablePartialRendering="true", and for your updatepanel, add Mode="Always".


Neither of those things should be necessary. (They're both the defaults.) Also, it's "UpdateMode" now (not "Mode" as it was in early CTPs).

My guess is that something's wrong in your web.config... did you start from the "ASP.NET AJAX-Enabled Web Site" template? Are there any JavaScript errors on the page when you first load it?


Steve Marx:

Neither of those things should be necessary. (They're both the defaults.) Also, it's "UpdateMode" now (not "Mode" as it was in early CTPs).

My guess is that something's wrong in your web.config... did you start from the "ASP.NET AJAX-Enabled Web Site" template? Are there any JavaScript errors on the page when you first load it?

You are right, I didn't start a new web site with "ASP.NET AJAX-Enabled Web Site" template. I adjusted web.config manually, and it works.

ASP.NET Ajax and VisualStudio2005

Hi there,

I've recently been experimenting with ASP.NET Ajax.
I'm able to create an Ajax Enabled website however Visual Studio doesn't seem to recognize the Asp.NET Ajax components...

When I'm viewing the web page in HTML format it doesn't even recognize the <asp:ScriptManager>.
What's really getting to me is that it doesn't recognize the<asp:UpdatePanel> nor the <contenttemplate>...andeverything within these tags, even though they are regular components(like text boxes and panels), shows up as errors.

Finding real problems in the HTML is difficult because there are so many error-swigglies underlining everything.


The site is works very well...and despite the fact that all theseerrors are listed, Visual Studio still compiles and runs the site.


Is there a way to make Visual Studio recognize the ASP.NET Ajax components?

Thanks

-Frinny

Have you added the Ajax/ControlToolkit components to the VS toolbar?

Yes, I have added it to the toolbar.

The site uses a bunch of different extenders and makes use of the update panels.
It works nicely but Visual Studio is showing the errors even though there are no errors.


That's odd.

When I enable Ajax, or ControlTookit, on existing asp.net pages the toolbar changes and the directives in the web.config seem to always do the trick.


So you don't see red-squggly error indicators when viewing the aspx as html?

Am I missing something? Did I not set this up correctly?


Have you registered the assembly in your aspx page?

<%

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


Yes I have <%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="ajaxToolkit" %> at the top of my pages.

This problem has been solved.

I was running Visual Studio 2005 without Service Pack 1.
Once I installed SP1 everything worked as it should...no more errors are showing up.

Thanks for all your help and advice!


-Frinny


Thanks for reporting back...You'll no doubt help a lot of others.Wink

Saturday, March 24, 2012

Asp.net 2.0 Ajax Gridview

Hi,

I was trying to create GridView with Ajax. I am using ASP.net 2.0 with Ajax Extensions installed.

I have Page already running with Gridview in it, I just want to enable Ajax for that.

So, I did..

1. Add ScriptManager tag to page from Toolbox <asp:ScriptManager ID="ScriptManager1" runat="server" />
2. Add UpdatePanel around GridView

<asp:UpdatePanel ID="udpOrderDetails" runat="server">
<ContentTemplate>
<asp:GridView
id="gvOrderDetails" runat="server"
DataSourceID="sqldsOrderDetails" AutoGenerateColumns="false">
</ContentTemplate>
</asp:UpdatePanel>

When I run the page, nothing happning!!!
Before I add these tags, Paging used to work in GridView, but now even paging is not working...

Can somebody help me to solve this issue??

Thanks

did you add the script manager inside the form tag and before any other controls?


I'm assuming there's more to the GridView code, since the tag isn't self closed and AutoGenerateColumns is false. If it's not too big, can you show the full code inside your UpdatePanel's ContentTemplate?


Tell me one thing.

Does your data in grid view are coming properly .

and Is it the problem that even after implementing update panel your whole page is loading again.

Please explain your problem.


you haven't shown code and your description could be for a few different problems, but if the gridview is able to initially load within the update panel, and then clicking on say a paging button makes the grid view disappear, then it is almost definitely a viewstate problem.


Hi,

I'd like to add one to those opinions above, please also make your configuration is correct.

You may refer to this documentation for more information: http://asp.net/AJAX/Documentation/Live/ConfiguringASPNETAJAX.aspx

Wednesday, March 21, 2012

ASMX Web service

Hi all,

I would like to create an ASP.Net Atlas application that will call a remote web service. I have checked a few samples and I have only seen examples where the web service sits on the same project as the Atlas application. Is there a way of calling a single remote web service with ATLAS or do I have to use a bridge?

Thanks

Regards

Stephanie

Never tryed, is this going to work?

<atlas:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<atlas:ServiceReference Path="http://somedoamin/someApp/WebService.asmx" />
</Services>
</atlas:ScriptManager>


I believe that should work if that cross domain webservice is an atlas webservice and:

1) The iframehandler is registered in your web.config.

<add verb="*" path="iframecall.axd" type="Microsoft.Web.Services.IFrameHandler" validate="false"/>


2) You have a WebOperation attribute on your web service that allows crossdomain posts (third parameter to the attribute constructor) i.e.

[WebOperation(true, ResponseFormatMode.Json, true)]

Hope that helps,
-Hao


Oh, and if your remote web service is not an atlas webservice, then I believe you would have to use a bridge.
I have tried that without any success

I have tried that without any success.

Xiyuan Shen:

Never tryed, is this going to work?

<atlas:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<atlas:ServiceReference Path="http://somedoamin/someApp/WebService.asmx" />
</Services>
</atlas:ScriptManager>


Hi,

The server where ATLAS app will be and the server where the web service will be are on the same domain, same site.

Is there another solution for that case?

Thanks

Stephanie

HaoK:

I believe that should work if that cross domain webservice is an atlas webservice and:

1) The iframehandler is registered in your web.config.

<add verb="*" path="iframecall.axd" type="Microsoft.Web.Services.IFrameHandler" validate="false"/>


2) You have a WebOperation attribute on your web service that allows crossdomain posts (third parameter to the attribute constructor) i.e.

[WebOperation(true, ResponseFormatMode.Json, true)]

Hope that helps,
-Hao


If I read Haok's comments right. I think the web service you refer to should run under asp.net 2.0, also the web.config file for the web service should be modified to use
Microsoft.Web.Services.ScriptHandlerFactory for handling web service request.

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
</httpHandlers>


So even if the webservice is on the same site and same domain, it stillneeds to be running atlas if you wish to access it using the atlasclient script proxies, so what Xiyuan mentions above is what you needon the web service site to enable generation of the client scriptproxies.

Hope that helps,
-Hao

Argh! Tabs disappear

Using the AJAX 1.0 release, I create a page with two tabs on it. The page displays great and a 'refresh' leaves the page untouched. However, if I click the submit button on the page, my two tabs disappear and I get the following javascript error:

Line: 218

Char: 9

Error: 'this.get_element().style' is null or not an object

Code: 0

URL:http://localhost/test/SetPassword.aspx

Any idea what might be causing this?

Thanks.

As I've worked with this, I've found that the error only occurs if the tabs are inside an update panel.


Yes this is a known issue - see this thread for discussion/fix:

http://forums.asp.net/thread/1549317.aspx

are we having drag and drop control

Hi,

Iam Mahender.Iam new 2 AjAX.Well recently i doenloaded and installed toolkit ajax and atlas.I want to create a drag and drop facility in my Webpage.it may any control part from panel.For example i took lists.plz help me up in this aspect

Hi,

We dont have any direct control for Drag/Drop functionality.

Beta2 will supports Drag/Drop features to webpart controls.

Please go through below links, you can find more info on that..

http://weblogs.asp.net/scottgu/archive/2006/11/08/ASP.NET-AJAX-1.0-Beta-2-Release.aspx

http://blogs.neudesic.com/blogs/david_barkol/archive/2006/11/07/631.aspx

http://www.neudesic.com/uploads/david_barkol/DNDSafari.jpg

Pradeep Kumar Bura