Showing posts with label controls. Show all posts
Showing posts with label controls. Show all posts

Monday, March 26, 2012

developing composite control that combines Ajax controls

Hi,

Is it possible to write a composite control that consists of UpdatePanels, and other control from Ajax Control Toolkit?

I would be happy to view some examples on developing this kind of control.

Thanks

Hello,

You can do this. It is possible.

I suggest that you use a scriptmanagerproxy in your control in case the page containing the control has a scriptmanager already. Aslo, you may have an easier time using the update panel in the containing page instead of in the control to get the ajax capabilities.

Good Luck,

Louis


Hi,

Thanks for the reply, do you suggest to put the composit control inside an update panel?

Im planning to build two build two composite controls:

one of them should contain an AutoCompleteExtender and other simple web controls . so I guess there wont be any problem with it.

but the other control will contain a TabContainer (from the Ajax Control Toolkit) I thought to put on each tab panel's content template an update panel (to reduce the amont of rerendered data, and save bandwith)

do you think that in this case its better to locate the whole TabContainer inside one UpdatePanel?

Thanks,

Tal


Yes, I suggest not including the update panel in the usercontrol.


Hi,

Im writting a composite control as I described in my first post (combines AutoCompleteExtender and FilteredTextBoxExtender and a TextBox)

I wrote the following Render function :

1 SearchAutoComplete =new AutoCompleteExtender();2 SearchAutoComplete.ID ="SearchAutoComplete";3 SearchAutoComplete.MinimumPrefixLength = 3;4 SearchAutoComplete.BehaviorID ="AutoCompleteBehavior";5 SearchAutoComplete.EnableCaching =true;6 SearchAutoComplete.CompletionSetCount = 5;7 SearchAutoComplete.UseContextKey =true;8 SearchAutoComplete.ServiceMethod ="GetCompletionList";9 SearchAutoComplete.TargetControlID ="SearchTextBox";10//SearchAutoComplete.OnClientItemSelected = "";1112 SearchFilteredTextBox =new FilteredTextBoxExtender();13 SearchFilteredTextBox.ID ="SearchFilteredTextBox";14 SearchFilteredTextBox.TargetControlID ="SearchTextBox";15 SearchFilteredTextBox.BehaviorID ="FilteredTextBoxBehavior";16 SearchFilteredTextBox.FilterType = AjaxControlToolkit.FilterTypes.Custom | FilterTypes.Numbers;1718 SearchByNameLabel =new Label();19 SearchByNameLabel.ID ="SearchByNameLabel";20 SearchByNameLabel.Text = Resources.Resource.SearchByName;2122 SearchByNumberLabel =new Label();23 SearchByNumberLabel.ID ="SearchByNumberLabel";24 SearchByNumberLabel.Text = Resources.Resource.SearchByNumber;2526 SearchTextBox =new TextBox();27 SearchTextBox.ID ="SearchTextBox";2829this.Controls.Add(SearchAutoComplete);30this.Controls.Add(SearchFilteredTextBox);31this.Controls.Add(SearchByNameLabel);32this.Controls.Add(SearchByNumberLabel);33this.Controls.Add(SearchTextBox);
1 AddAttributesToRender(writer);23 writer.AddAttribute(4 HtmlTextWriterAttribute.Cellpadding,5"1",false);6 writer.RenderBeginTag(HtmlTextWriterTag.Table);7 writer.RenderBeginTag(HtmlTextWriterTag.Tr);8 writer.RenderBeginTag(HtmlTextWriterTag.Td);9 SearchByNameLabel.RenderControl(writer);10 writer.RenderEndTag();11 writer.RenderBeginTag(HtmlTextWriterTag.Td);12 SearchByNumberLabel.RenderControl(writer);13 writer.RenderEndTag();14 writer.RenderBeginTag(HtmlTextWriterTag.Td);15 SearchAutoComplete.RenderControl(writer);16 writer.RenderEndTag();17 writer.RenderBeginTag(HtmlTextWriterTag.Td);18 SearchFilteredTextBox.RenderControl(writer);19 writer.RenderEndTag();20 writer.RenderEndTag();21 writer.RenderEndTag();22

and got the following Exception:

"Error: Sys.ArgumentException: value must not be null for controls and behaviors.

parameter name:element"

Any idea?

Thanks


hi,

change

SearchAutoComplete.TargetControlID ="SearchTextBox"

to be

SearchAutoComplete.TargetControlID = SearchTextBox.ClientID

the script is hassling you about being unable to find the targetControl


Hi,

Thanks for your reply.

I want my WebMethod to be integrated with the CompositeControl (Im not intersted in Exposing it as a top level property).

How can I embed a web-service with the control (I prefer using PageMethod fo GetCompletionList). ?

I read somewhere that I should write a custom HttpHandler ( if i want my CompositeControl to use my embedded webservice) , It seems complicated , do you have en example for this?

or better , a solution for how I can use an "embedded" PageMethod?

Thanks,

Tal


Hi Tal,

It's not recommended to embed the pageMethod inside a UserControl.

By default, a client can't request for a user control( with extension .ascx) directly, it's blocked by the a special handler that prevents accessing. It's not recommend to change this behavior.

May be you are trying to implement a user control that is easy to maintain and use, but if the user has to pay more to get accustom to this.


Hi,

Im Writting a CompositeControl not a UserControl.

so actually Im trying to "embed" the PageMethod or Web-service method (GetCompletionList method) inside the DLL of my CompositeControl.

Is there a way to solve this?

(im not interesting in exposing the AutoCompleteExtender's ServiceMethod property)

I want that the logic of geting the completion results will be a part of my CompositeControl.

Thanks


It's also not allowed to access a assembly on client side directly.

There should always an endpoint( a class implement IHttpHandler interface ) on the server be responsible for processing a request. You may implement a class and use it to invoke the method in the dll.


Hi,

Do you have any refferences for how to implement such a class?

I have know idea how to write an HttpHandler that invokes a web-service that is embedded in a DLL...

Thanks


Hi,

Just create a class that implementIHttpHandlerinterface. And you may refer to the ScriptResourceHandler class in thesource code of ajax extension for a practical implementation of it.


Hi,

Thanks for the reply. I will have a look at the source code of ajax extension.

Do you think I should also implement an HttpHandlerFactory?

As I understand my custom HttpHandlerFactory will check all *.asmx requests,

if the asmx request is for my AutoComplete web service return my custom HttpHandler, otherwise return the default one.

is this correct?


Not necessary, you may register the Handler to a specific file name in web.config.

But if you plan to use .asmx, why don't you add a web service directly. It's a implicit httpHandler.


Hi,

what do you mean by "adding the web-service directly"?

Developing Atlas Friendly Controls

I'm working a custom control that requires client-side javascript. Is there a list of best practices for making a control Atlas friendly?

I'm currently using the ClientScriptManager to register the necessary scripts, but something is not working properly.

hello.

though i still haven't developed none, i think that an atlas control is supposed to implement the IScriptControl interface (this interface introduces a method that is called when you need to register the xml-script emitted by the control).

since there still is no info about it, i think that your best option is to use reflector and see how they implemented the atlas server controls.


If you are developing a server-side control that wishes to perform client-side logic or behavior then you can certainly approach it from a number of angles:

Simply generate your own JavaScript and register with the clientscript on the Page. then tie up your client-side events to functions therein

Design time rendering of TabPanels?

Hi-

Are TabPanels supposed to render at design time? Mine aren't, even though other AjaxToolkit controls are on the same page and are rendering properly (like AccordionPanes and UpdatePanel). It doesn't seem to matter whether the TabPanels are on their own or within another AjaxToolkit control.

Thanks,

Neil

Hi,

Tabs doesn't have proper design support yet. It's one of the highest voted bugs and the Tabs author is busy working on a fix.

Thanks,
Ted

Deriving custom control from UpdatePanel doesnt work

I previously created multiple controls by deriving them from UpdatePanel using ATLAS (before BETA). Today I tried switching one of the controls to BETA and now I am getting PageRequestManagerParserErrorException error.

I created a very simple control to reproduce the problem:

===================================

namespace AtlasControls
{
[ToolboxData("<{0}:TestAtlasCtrl runat=server></{0}:TestAtlasCtrl>")]

public class TestAtlasCtrl : UpdatePanel, INamingContainer
{

public TestAtlasCtrl()
{
}


protected override void Render(HtmlTextWriter writer)
{
writer.WriteLine("Custom text is here...");
base.Render(writer);
}
}
}

=========================================

Here is the test page where I use the control:

==========================================

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="AtlasBeta_Test" %>
<%@dotnet.itags.org. Register TagPrefix="Custom" Namespace="AtlasControls" %
<!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 runat="server" ID="scriptManager" />
<div>
<Custom:TestAtlasCtrl ID="dlgForgotPassword" runat="server">
<ContentTemplate>
<asp:panel ID="panelForgotPasswordForm" runat="server">
<asp:TextBox id="txtEmail" Columns="40" MaxLength="255" CssClass="xTextBox" runat="server"/>
<asp:RequiredFieldValidator ID="vtxtEmail" ControlToValidate="txtEmail" EnableClientScript="false" runat="server" ErrorMessage="Email is required"></asp:RequiredFieldValidator>
<br /><br />

<center>
<asp:Button ID="btnOk" runat="server" CssClass="xSubmitPrimary" Text="OK" OnClick="btnOk_Click"></asp:Button>
</center>
</asp:panel>
</ContentTemplate>
</Custom:TestAtlasCtrl>
</div>
</form>
</body>
</html>
===================================

When I click OK in the form without entering 'Email' I get PageRequestManagerParserErrorException error. The error hints that it can be caused by Response.Write() and overriding HttpHandlers, but I am not doing any of that.

Regards,

Eric Popivker

I tested your codes and found the same issue as you said in your post.The issue is in the code line "writer.WriteLine("Custom text is here...");".In Ajax controls,you can not use the functionality which is similar toResponse.Writebecause there is no postback happening if you don't specify triggers.
Wish this can help u.

Saturday, March 24, 2012

Derived Validator Controls Bug

Found an obscure bug in the derived validator controls that work with AJAX. I'm toying with a response filter that strips unneeded newlines and tabs from the rendered response, and it worked great until I used the derived validor controls for AJAX; then I received javascript errors.

The problem is a missing ; that works fine unless the \n is stripped out. Easy fix in ValidatorHelper.cs, just add the ; in the function below...

public static void DoValidatorArrayDeclaration(WhidbeyBaseValidator validator, Type validatorType) {
string element = "document.getElementById(\"" + validator.ClientID + "\")";
ScriptManager.RegisterArrayDeclaration(validator, "Page_Validators", element);

ScriptManager.RegisterStartupScript(validator, validatorType, validator.ClientID + "_DisposeScript",
String.Format(
CultureInfo.InvariantCulture,
@dotnet.itags.org."
document.getElementById('{0}').dispose = function() {{
Array.remove(Page_Validators, document.getElementById('{0}'));
}}; <-- *** PROBLEM HERE ***
",
validator.ClientID), true);
}

...and everything works fine.

Sean

Hi Sean,

Thanks for your sharing.
Please reply to this thread and mark your post as answer so that it will contribute more to others.
Thank you.

I contacted Matt Gibbs (MS) and he said it was too late for this to make it into the next update to System.Web, but the fix will make it into Orcas.

Sean

Deployment

I decided to start learning how to use the AJAX controls in my ASP.NET pages, so I made a simple website with a few controls on there to test. It works fine when I run the page from localhost, but when I tried to use it from a webspace that I have it gives me some errors such as:

Line 28: <compilation debug="true">
Line 29: <assemblies>
Line 30: <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 31: <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
Line 32: <add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

Here is the web address of the site if you want to try to run it:

http://cpt255.tech.purdue.edu/TA2/EGIS/EGIS.aspx

Hi,

are you sure the ASP.NET AJAX Extensions were installed on the server? If not, it won't work. Please check with the administrator or hosting company to be sure.

Grz, Kris.


Is ASP.NET AJAX installed in the environment you are using? I got that error on our first deploy of AJAX and it was because the sysadmin's didn't install AJAX yet. Also see if you can put the DLL's in a 'bin' folder in your app if they haven't deployed it to the server yet. That should clear it up...

Dapanther


Dang Kris, you beat me to this one LOL

Dapanther


I didn't realize that the extensions had to be installed on the web server as well. Thanks for the info guys.

TheSwazz:

I didn't realize that the extensions had to be installed on the web server as well.

Yes, the extensions get deployed in the GAC of the server/machine. It's under Microsoft support meaning it'll get supported for the next 10 years, 24/24, 7/7.

Grz, Kris.

Deploying Styles with your controls

I have found a way of deploying styles for an ajax control which I thought might be useful to others. I found this while examining the source code of the AjaxControlToolkit which is available as an open source project. you will need a reference to this assembly in order to use this method. These are the steps to be taken.

1.Include your css file in your controls project, set it as an embeded resource and and an assembly attribute for your control refrencing said css file. If you don't know how to do this google for it, a million people have posted on this subject.

[assembly:WebResource("MyControls.Web.Controls.DropDown.DropDown.css","text/css", PerformSubstitution =true)]

2. add the ClientCssResource to your class

[ClientCssResource("MyControls.Web.Controls.DropDown.DropDown.css")]

3. In your Prerender method for your control call the RegisterCssReference method of the static class ScriptObjectBuilder which is part of the AjaxControlToolkit

ScriptObjectBuilder.RegisterCssReferences(this);

This ScriptObjectBuilder class is an interesting class, it looks like it keeps a cached set of refrences to the css files included so as not to included them more than once. It adds the list of css refrences it has compiles as link tags to the <HEAD> of your page. Make sure your <HEAD> has runat="server" set. If you need a more complete example of how this is used , you might read the cs source code for the DropDownExtender in the toolkit.

Thanks fbaldoni!

I have been searching a half day to get this to work. This only part I had missing was step 3. Where in the AJAX documentation can I find that? No where. I just happen to stumble upon your post.


Glad to be of serviceSmile

deploying apps using AJAX

These controls in the AJAX toolkit seem really nice, and I was able to get them working in my development environment. I was disappointed that when I published my app to the web server though it no longer worked. I'm trying to understand exactly what needs to be done on the server to get it working. I don't have a lot of control over what gets installed on the server, so this may be a problem. The error message I got indicated it was blowing up from these lines in my web.config:

<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

Appreciate any help on how I can successfully deploy this app using FTP (if possible).

Thanks,

***

Hi dschroth,

You need to make sure that the system.web.extensions dll is installed in the GAC on your server. This will solve your problem probably!

Regards,


hello.

any chance of copying the stack error info and putting it here?


Server Error in '/nmp' Application.

Configuration Error

Description:An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message:Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error:

Line 12: <compilation debug="true" explicit="true">Line 13: <assemblies>Line 14: <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>Line 15: <add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> Line 16: <add assembly="System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>


Source File:D:\sites\NMP\web.config Line:14

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

WRN: Assembly binding logging is turned OFF.To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.Note: There is some performance penalty associated with assembly bind failure logging.To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].



Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210

Server Error in '/nmp' Application.

Configuration Error

Description:An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message:Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error:

Line 12: <compilation debug="true" explicit="true">Line 13: <assemblies>Line 14: <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>Line 15: <add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> Line 16: <add assembly="System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>


Source File:D:\sites\NMP\web.config Line:14

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

WRN: Assembly binding logging is turned OFF.To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.Note: There is some performance penalty associated with assembly bind failure logging.To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].



Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210

Hello.

by looking at the stack trace, it looks like you don't have the AJAX dll installed on the GAC. If you're able to run your web app at full trust, then you should copy the ajax dll into your bin folder (note that this will only work if you're able to configure your app to run at full trust)


When I published the app, it put both AJAXExtensionsToolbox.dll and AjaxControlToolkit.dll into the bin folder. Are they the AJAX dll you mean? If so, how can I configure the app to run at full trust?

Thanks for your help!


nope,

the system.web.extensions

succes!

Regards,


Whoever owns your server has to do it via the code access security settings, or else (as stated) install the dll to the GAC on the server. If you're working w/ a hosting company just renting a virtual directory, then the company will either advertise that they support AJAX extensions, or else you're probably out of luck w/ that one.


i hate to be stupid, but how do you install a dll to the GAC?


HI dschroth,

check the following link:

http://msdn2.microsoft.com/en-us/library/ex0ss12c(VS.80).aspx

Regards,


Sorry maybe a bit overkill open Visual studio command prompt and add:
gacutil /i YOURDLL.dll
Regards,

hello.

in this case, running tha ajax installation pacakage will do just that.

adding a dll to the gac is simple: you just need to drop it in windows\assembly folder or run the gacutil from the command line.


thanks everyone for your help - I guess it's easy when you know how. apparently all I needed to do was drop the System.Web.Extensions dlls into the bin folder on my development machine, and then the publish process put them on the server.

***


I am having a similar problem with trust issues. I run the site in house on a server so I really do not have a problem with full trust issues. The site runs on IIS 5.1. What do I need to do to set for Full Trust?

Thanks for the information.

Wednesday, March 21, 2012

Delaying Content Load using Timer and UpdatePanel

I've created a custom template control that I'm trying to use to delay content loading on a page for long running controls.

Here:

1public sealed class DelayedContentLoader : WebControl, INamingContainer
2 {
3private MultiView mvContent =new MultiView();
45private int interval = 10000;
6public int Interval
7 {
8get {return interval; }
9set { interval =value; }
10 }
1112public delegate bool LoadContentHandler();
13public LoadContentHandler OnLoadContent;
1415private ITemplate loadingTemplate;
16 [TemplateContainer(typeof(LoadingView))]
17public ITemplate LoadingTemplate
18 {
19get {return loadingTemplate; }
20set { loadingTemplate =value; }
21 }
2223private ITemplate loadFailedTemplate;
24 [TemplateContainer(typeof(LoadFailedView))]
25public ITemplate LoadFailedTemplate
26 {
27get {return loadFailedTemplate; }
28set { loadFailedTemplate =value; }
29 }
3031private ITemplate contentTemplate;
32 [TemplateContainer(typeof(ContentView))]
33public ITemplate ContentTemplate
34 {
35get {return contentTemplate; }
36set { contentTemplate =value; }
37 }
3839protected override void OnInit(EventArgs e)
40 {
41if (loadingTemplate !=null)
42 {
43 LoadingView loadingViewContainer =new LoadingView();
44 loadingTemplate.InstantiateIn(loadingViewContainer);
45 mvContent.Views.Add(loadingViewContainer);
46 }
4748if (contentTemplate !=null)
49 {
50 ContentView contentViewContainer =new ContentView();
51 contentTemplate.InstantiateIn(contentViewContainer);
52 mvContent.Views.Add(contentViewContainer);
53 }
54else
55 throw new Exception("A Content Template must be specified.");
5657if (loadFailedTemplate !=null)
58 {
59 LoadFailedView loadFailedViewContainer =new LoadFailedView();
60 loadFailedTemplate.InstantiateIn(loadFailedViewContainer);
61 mvContent.Views.Add(loadFailedViewContainer);
62 }
63 }
6465protected override void OnLoad(EventArgs e)
66 {
67 UpdatePanel updatePanel =new UpdatePanel();
68 updatePanel.UpdateMode = UpdatePanelUpdateMode.Always;
6970 mvContent.ActiveViewIndex = 0;
7172 updatePanel.ContentTemplateContainer.Controls.Add(mvContent);
7374 Timer timer =new Timer();
75 timer.ID ="timerDelayedContentLoader";
76 timer.Interval = interval;
77 timer.Tick +=new EventHandler(timer_Tick);
7879 updatePanel.ContentTemplateContainer.Controls.Add(timer);
8081 Controls.Add(updatePanel);
82 }
8384public override Control FindControl(string id)
85 {
86 Control ctrl = mvContent.Views[1].FindControl(id);
87if (ctrl !=null)
88return ctrl;
8990 ctrl = mvContent.Views[2].FindControl(id);
91if (ctrl !=null)
92return ctrl;
9394 ctrl = mvContent.Views[0].FindControl(id);
9596return ctrl;
97 }
9899private void timer_Tick(object sender, EventArgs e)
100 {
101bool loadedContentSuccessfully =false;
102if (OnLoadContent !=null)
103 loadedContentSuccessfully = OnLoadContent();
104105// Stop the timer.106 Timer timer = FindControl("timerDelayedContentLoader")as Timer;
107if (timer !=null)
108 timer.Enabled =false;
109110int visiblePlh = loadedContentSuccessfully ? 1 : 2;
111 mvContent.ActiveViewIndex = visiblePlh;
112 }
113 }

The control does work, but once the first 'panel' loads I'm getting this error:

Error: Sys.ScriptLoadFailedException: The script 'http://localhost:2059/WebResource.axd?d=2969z1Qx3dbsV5nCF1BRcXhpF5ub86-cDZ-FaGYdZEBQbKzZVJb7tl6DB7CRlXIMyp8MDajf0oi_5PQ_Zb35Pg2&t=633181289164114804' failed to load. Check for:
Inaccessible path.
Script errors. (IE) Enable 'Display a notification about every script error' under advanced settings.
Missing call to Sys.Application.notifyScriptLoaded().
Source File: http://localhost:2059/ScriptResource.axd?d=w7roB_KjU8DhSirRDxfFxPRhP-DUqImf_4Nd1a5Co3kx1o511QAFqGXxMtkfZR8UkArHbaLDYRdK8lHjJK-ARWQArhEXy5Ydco_GHuMUgH41&t=633120912402558276
Line: 3311

The error kills all of the JavaScript on the page - others delayed content loaders stop loading and all other AJAX stuff ceases to work. The line that is referenced is this line #10 below:

// MicrosoftAjax.js
// Microsoft AJAX Framework.
1function Sys$_ScriptLoader$_raiseError(multipleCallbacks) {
2 var callback = this._scriptLoadFailedCallback;
3 var scriptElement = this._currentTask.get_scriptElement();
4 this._stopLoading();
5
6 if(callback) {
7 callback(this, scriptElement, multipleCallbacks);
8 }
9 else {
10throw Sys._ScriptLoader._errorScriptLoadFailed(scriptElement.src, multipleCallbacks);
11 }
12 }

Is there anything that can be done here? By the way, this control is inside of a Web Part. If I remove all the Web Part stuff, I don't get the error but only one of my delayed content loading controls finishes loading.

Any help would be much appreciated.

Thanks!

Has anyone tried to do this?


Hi

Ok,Just do it like this:

<%@. Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
TextBox1.Text = DateTime.Now.ToString();
}
</script>

<script type="text/javascript">
function delayLoad()
{
document.getElementById("<%= Button1.ClientID %>").click();
document.getElementById("<%= UpdateProgress1.ClientID %>").style.display = "block";
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body onload="setTimeout('delayLoad()',3000)">
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<div visible="true"><asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
Waiting...........
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</form>
</body>
</html>

Thanks:)


How is that the same as what I was trying to do? Unless you're saying I need to have my update panel's UpdateMode set to conditional. Are you?


Hi,

In my code,I delay by 3 second to load the content.

It's the same as following code:

<%@. Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
TextBox1.Text = DateTime.Now.ToString();
}

protected void Timer1_Tick(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
TextBox1.Text = DateTime.Now.ToString();
Timer1.Enabled = false;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" 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" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<div visible="true">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div>
<asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
Waiting...........
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</form>
</body>
</html>

A timer for an updatepanel.we can do it.

I know you just want to creat a contorl to include a updatepanel and a timer,I'll do it for you later.


OK

I have done it for you now.

bur I 'm using webcontrol rather than server control,I think it is more simple:)

The code :

The page:

<%@. Page Language="C#" %>

<%@. Register src="http://pics.10026.com/?src=WebUserControl5.ascx" TagName="WebUserControl5" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected bool WebUserControl5_1_LoadContent(object sender, EventArgs e)
{
try
{
((WebUserControl5)sender).myContent = "OK..........";
}
catch
{
return false;
}
return true;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<uc1:WebUserControl5 ID="WebUserControl5_1" runat="server" OnLoadContent="WebUserControl5_1_LoadContent" />
</div>
<div>
<uc1:WebUserControl5 ID="WebUserControl5_2" runat="server" OnLoadContent="WebUserControl5_1_LoadContent" />
</div>
<div>
<uc1:WebUserControl5 ID="WebUserControl5_3" runat="server" OnLoadContent="WebUserControl5_1_LoadContent" />
</div>
<div>
<uc1:WebUserControl5 ID="WebUserControl5_4" runat="server" OnLoadContent="WebUserControl5_1_LoadContent" />
</div>
</form>
</body>
</html>

The control:

<%@. Control Language="C#" ClassName="WebUserControl5" %>

<script runat="server">
protected void Timer1_Tick(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
TextBox1.Text = DateTime.Now.ToString();
bool loadedContentSuccessfully = false;
if (LoadContent != null)
loadedContentSuccessfully = LoadContent(this,e);

// Stop the timer.
Timer1.Enabled = false;

int visiblePlh = loadedContentSuccessfully ? 1 : 2;
MultiView1.ActiveViewIndex = visiblePlh;
}

public delegate bool LoadContentHandler(object sender, EventArgs e);
public event LoadContentHandler LoadContent;
public string myContent
{
set
{
TextBox2.Text = value;
}
}
</script>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="LoadingView" runat="server">
Loading...........</asp:View>
<asp:View ID="ContentView" runat="server">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></asp:View>
<asp:View ID="LoadFailedView" runat="server">
Failed...........</asp:View>
</asp:MultiView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
Waiting...........
</ProgressTemplate>
</asp:UpdateProgress>

Works cool.....:)

Thanks


Not exactly what I was looking for since I want to build something that's a bit more re-usable than a simple ASCX. Another issue I found was that if I had two instances of the same templated control, say one names 'ctrl1' and the other named 'ctrl2' the timer would just keep updating one or the other like this...

page loads

--ctrl 1 loaded after delayed

--ctrl2 loaded after delayed (ctrl1's content hidden)

--ctrl1 loaded after delayed (ctrl2's content hidden)

--and so on

Very strange.


Delayed content loading is BRILLIANT!....IF you arent delaying an async callback such as a databind. What if you would like to load the graphical content FIRST and then populate a combobox with its records as the delayed content - The browser freezes until the databind is complete! Thats fine if your only VIEWING the page but what if the user would like to start entering input whilst waiting for a Suburb Dropdown to populate....


Hi Delorenzo,

Im also trying for the same. Im trying to delay content loading using ajax controls in Custom control. I have no Idea how to do it, if u got the solution for this problem then plz let me knw.

Thanks in Advance,

Rajak Shaik.


I couldn't get this to work exactly as I wanted it to, so I scrapped it and switched to a solution using JavaScript and Web Services with Prototype and Scriptaculous (for my animation). The solution works great!



Hi Delorenzo,

Thanks for replying. Can u plz tell me how it can be done using Javascript and Webservices, if possible with code.

Thanks in Advance,

Thanks & Regards,

Rajak Shaik.


Another question:

Can I do something like this below? I'd like to update the time as a process is running. However, the time on the edit box only changes (or updates) on the last one. I've tried UpdatePanel1.Update() as well and this doesn't seem to get the refresh to happen either.

protected void Timer1_Tick(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
TextBox1.Text = DateTime.Now.ToString();
System.Threading.Thread.Sleep(3000);
TextBox1.Text = DateTime.Now.ToString();
System.Threading.Thread.Sleep(3000);
TextBox1.Text = DateTime.Now.ToString();
System.Threading.Thread.Sleep(3000);
TextBox1.Text = DateTime.Now.ToString();
Timer1.Enabled = false;
}

Thanks,

Gary


Hi Gary...

I am a little unclear on what you are trying to achieve. Did you want to show the amount of time that a process takes to complete? or would you just like to show the current time and refresh it every 3 seconds?

Perhaps set the timer to 3000 and then:

protected void Timer1_Tick(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToString();

Updatepanel.update

}

------
Codey


Well- not exactly so let me ask my real question. Smile I hate to get a little off the posting subject, but hopefully it's helpful.

Inside the timer I'd like to run a loop and when each loop is done then I'd like to update the date in the text box. Actually I don't really want to use a timer either, but if I can make it work that way that would be ok too. It only seems to update the text box at the end and doesn't want to update it after each loop.

protected void Timer1_Tick(object sender, EventArgs e)
{

for (int i = 0; i < 10; i++)

{

CallProcess(i);

TextBox1.Text =DateTime.Now.ToString();

UpdatePanel1.Update();

}

Thanks!!

Gary


The Update wont occur until the postback is complete, therefore the final value that you assign the textbox will be the value that is displayed.

Even though you are forcing an update on the updatepanel, that update wont display until the page completes its postback.

I see that you are trying to place a time stamp in a textbox evertime the CallProcess routine completes.

You probably need to consider multiple textboxes and a Select Case statement:

For i = 1To 10

CallProcedureHere(i)

SelectCase i

Case 1
Textbox1.text = Now
Case 2
textbox2.text = Now

EndSelect

Next

Delay content loading using ajax in Custom control?

Hi All

I Want to Delay content loading using ajax if the running controls are taking so much time in Custom control. I did this in WebPage but i have no idea about how it should be done in an Custom control. The data in custom control is coming from webservice which is taking long time, in the mean while i want to display an image saying "loading..." for it using ajax. Can anyone plz help me out.

Thanks in Advance,

Thanks & Regards,

Rajak Shaik.

Hi

I assume that you are not familiar with the AJAX UpdateProgress control.

Please find this link to see a demo and sample code. You can do it exactly what you wanted to do with this.

http://www.asp.net/AJAX/Documentation/Live/tutorials/UpdateProgressTutorials.aspx


hello.

well, that won't help him.

even though i don't agree there are some guys that are doing something like this:

1. wrap the part that has the user control with an updatepanel

2. don't make the call for loading the data when the user controlo is loaded for the 1st time

3. when the page loads on the client, they refresh the updatepanel (if you have an updateprogress, it'll kick in automatically in this case)

4. during a partial postback, you can perform the call

notice that I'm against this approach, since i believe that ajax programming should envolve mainly client side programming...


Hi,

This question has been discussed athttp://www.codeproject.com/Ajax/DelayedContentLoading.asp &http://forums.asp.net/t/1127147.aspx

Please check out these links to get some idea,

Best Regards,


Hi All,

Thanking u all for replying. I able to do this using UpdateProgress, and Script. Actually my requirement was little bit changed, i.e. i was asked to Delay content loading in case of UserControl, which is having Custom controls init. Whenever an event of Usercontrol fired then i need to display this image 'loading..." until the data comes. So i have written the code below on the webpage(which is having this Usercontrol in it).

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

<ContentTemplate>

<uc1:PropertiesID="usrDestination"runat="server"PageUri=""ParentUri=""/>

</ContentTemplate>

</asp:UpdatePanel>

<asp:UpdateProgressID="UpdateProgress1"AssociatedUpdatePanelID="UpdatePanel1"runat="server">

<ProgressTemplate>

<asp:imagerunat="server"ID="image2"ImageAlign="middle"ImageUrl="spinner.gif"/>

<asp:Labelrunat="Server"ID="label2"Font-Size="smaller"ForeColor="orange"Text="Loading..."/>

</ProgressTemplate>

//Script in the Body

<scripttype="text/javascript">

Sys.Application.add_load(ApplicationLoadHandler);

function ApplicationLoadHandler(sender, args)

{

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_initializeRequest(initRequest);

prm.add_endRequest(endRequest);

}

function initRequest(sender, args)

{

$get('UpdateProgress1').style.display ='block';

}

function endRequest(sender, args)

{

$get('UpdateProgress1').style.display ='none';

}

</script>

This is Working fine for me. I would be happy if this code helps to anyone that is in need. Thank u once again for u all for helping me in finding out the solution for this problem.

Thanks & Regards,

Rajak Shaik.

Default atlas:UpdatePanel Default Behavior

I feel that the default behavior for an update panel should include disabling the content/controls it contains while an update is occuring (Make all the anchors turn into divs, disable all form inputs, etc.. etc..), or at least an option for toggling that functionality. Then the atlas:UpdateProgress could contain a cancel button that would re-enable the update panel's content. It seems to me that most people would expect that behavior and it would really help developers AJAX code be a little tighter.

hello.

hum...i think that you can do that by injecting javascript on the page during the events generated by the pagerequestmanager client class...another option would be to build an extender ;)


Well, I'm sure there are plenty of ways to do it; however, what I'm trying to say is it would be nice if either (A) it was the default behavior of an atlas:updatepanel while it is updating or (B) there was a property that could easily be set to accomplish this disableDuringUpdate="true" or something like that.

My reasoning is simply that I believe many people will end up writing that code themselves while one of the main goals of .NET seems to be to write less code and make it easier for a developer to produce results faster. I don't think it would be very difficult to include with the AJAX/Atlas extensions.

Declaring controls in javascript

Is it possible to create the various toolkit controls in javascript? Specifically looking at the AutoCompleteExtender and the CollapsiblePanelExtender. My ultimate goal is to see if the controls could be used within an Atlas gadget.

Thanks,
Kyle

You can consume the .JS behavior files of the Toolkit controls directly for use outside ASP.NET (among other things), but that's not one of the primary scenarios for us, so I'm afraid we don't have much of documentation/samples for the relevant scenarios. You might find more information on this by searching the Atlas forums here and also the web as I recall someone showing how to do this with PHP or something...
Hi Kyle,

Actually you can find a straightforward example inFAQ item #13.

Thanks,
Ted

That's awesome, Ted. I got it to work with the following code, which is basically a variation of what's in the FAQ:

<script language="javascript" type="text/javascript">
function onAddBehavior( )
{
var textbox = new Sys.UI.TextBox( $('TextBoxSimpleSearchTerm') );
var watermark = new AtlasControlToolkit.TextBoxWatermark( );
watermark.set_WatermarkText( "Enter a search term" );
watermark.set_WatermarkCssClass( "watermarked" );

textbox.get_behaviors( ).add( watermark );
watermark.initialize( );
}
</script>

I do have one problem, though. I called the onAddBehavior method in the body's onload event and at that point, it looks like the AtlasControlToolkit namespace has not been defined yet because I get an error: 'AtlasControlToolkit' is undefined. When I call the method in the onclick method for a button on the page, though, it works fine.

Another way I got it to work is by extracting the javascript file for the AtlasControlToolkit.ExtenderBase object, making it an explicit javascript file and referencing that on the page.

First question: where should I call the onAddBehavior method?

Second question: Is the base control extender javascript file explicitly available anywhere or is it embedded in the Microsoft.AtlasControlExtender assembly?

My ultimate goal is to see if I can make a Gadget that incorporates toolkit extenders so my guess is that I will have to reference this javascript file directly since as far as I know, you can't include server-side controls within a Gadget. Yesno?


Hi Kyle,

Glad you were able to get it working. For your first question, there are two ways to get code to run after "Atlas" has finished loading. You can either add a handler to theSys.Application.load event or use the (little known) fact that "Atlas" will automatically call a function on your page calledpageLoad if it is defined. So in your case, I think the easiest approach would be something like:
functionpageLoad() {
OnAddBehavior();
}
Your second question is easy too. If you get thelatest release of the Toolkit, you'll see that we've taken everything that was in the extender base and made it public. It's now all found in theAtlasControlToolkit project'sExtenderBase folder.

I haven't had any experience with gadgets, but from what I understand they support "Atlas" so all our extenders that rely primarily on JavaScript behaviors should be useful.

Thanks,
Ted

Oh bother, I knew you made everything public but assumed it was in the latest CTP and when I didn't see it there, I chalked it up to a wondrous and fantastical dream. Now have the latest source and there it is in all its glory.

Having some issues with Atlas Gadgets in general but that's a separate discussion. Thanks a lot for your help, Ted.