Showing posts with label documentation. Show all posts
Showing posts with label documentation. Show all posts

Wednesday, March 28, 2012

AJAX Beta 2 web.config

Is there any documentation describing the sections needed in the web.config file to implement asp.net ajax into a site? I have installed it and am using it happily but I want an explanation of each element that is in that web.config template and why it is required, what I dont know worries me!

Thanks!

This is an excellent question.

I am going to give an explaination off my head:

First off:DOCS.

<configSections>
<sectionGroup name="microsoft.web" type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="Microsoft.Web.Configuration.ScriptingSectionGroup, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="webServices" type="Microsoft.Web.Configuration.ScriptingWebServicesSectionGroup, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="Microsoft.Web.Configuration.ScriptingJsonSerializationSection, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
<section name="profileService" type="Microsoft.Web.Configuration.ScriptingProfileServiceSection, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
<section name="authenticationService" type="Microsoft.Web.Configuration.ScriptingAuthenticationServiceSection, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>

^^ This just defines how the config sections are laid out in the following markup in the config file.

The important stuff we should concentrate about is the inner section webServices and the sections below that (the outer ones just defines the layout of the config kinda (dumb sections that does nothing but define themselves ))

--

jsonSerialization,profileService,authenticationService are all on the same level. These actually have usable elements you can configure.

You should read the docs on what the classes are (they are vague though) but web.config found in C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025

has an actual section + comments:

<microsoft.web>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
--
<!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
and modified in Atlas applications, you need to add each property name to the setProperties and
getProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
</scripting>
</microsoft.web>

jsonSerialization section can have defined custom converters, if you have an object that you want to provice your own notation for, do it here.

I don't know too much about the other stuff, but it seems pretty straight forward...

--

Moving on:

<pages>
<controls>
<add tagPrefix="asp" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagPrefix="asp" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
<tagMapping>
<add tagType="System.Web.UI.WebControls.CompareValidator" mappedTagType="Microsoft.Web.UI.Compatibility.CompareValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.CustomValidator" mappedTagType="Microsoft.Web.UI.Compatibility.CustomValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.RangeValidator" mappedTagType="Microsoft.Web.UI.Compatibility.RangeValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.RegularExpressionValidator" mappedTagType="Microsoft.Web.UI.Compatibility.RegularExpressionValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
<add tagType="System.Web.UI.WebControls.RequiredFieldValidator" mappedTagType="Microsoft.Web.UI.Compatibility.RequiredFieldValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.ValidationSummary" mappedTagType="Microsoft.Web.UI.Compatibility.ValidationSummary, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</tagMapping>
</pages>

^^ <controls> will map the prefix 'asp' to the AJAX controls (mainly updatepanel, scriptmanager, updateprogress etc) GLOBALLY across the whole site, so you don't have to provide it in the directive on each page ( This is VERY useful to use on your own controls, this is a true blessing!)

The <tagmapping> will replace the stock ASP.NET validator controls with the ASP.NET AJAX ones. This is to override the original stock validator controls to make them work properly.

--

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>
</httpHandlers>

First one replaces all requests (post, get (etc?)) to asmx files to the ScriptHandlerFactory. This factory is undocumented, but I can tell that it switches between 2 handler factories (it wraps them on a condition)

First one of them is RestHandlerFactory (undocumented), this will get chosen if it is a rest (if pathinfo starts with "/js").

If not, it will choose the stockWebServiceHandlerFactory class.

ScriptResource,axd axd is AJAX' own handler for processing script resources. This seems to be well documented (compared to other ajax stuffStick out tongue).

--

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="Microsoft.Web.UI.ScriptModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" />
</handlers>
</system.webServer>


^^ This is the section for IIS 7.0 (or any web server that reads this section. maybe cassini?).

This will remove WebServiceHandlerFactory-ISAPI-2.0 and inject the script handlers / modules.

Some is documented, some is not. But this is probably to make the script stuff work, to use regular English. Big Smile

This is only from the top of my head. Some are facts, some are just my assumptions!

Anyway, hope it helps, and if it really is an answer to you,mark it as answer, thanks!


hello.

the final section will only be used by IIS 7 (and i do think that the web.config that comes with ajax beta 2 is not complete).

btw,?EmilChristopherMelar is there any contest with cool prizes or something like that? why are you asking for your answer to be marked at the end ofyour posts?
Because then you can see that a thread is really answered, so people can see that it doesn't need any more attention, duh.
hello.

well, didn't really know that there are people on this forum trying to find threads that need attention...

It's not about that. It's about aknowledging the answer so I don't have to follow it up anymore.

It is common sense and usage of news / forums to give a response on a successful / unsuccessful answer.

And what's the point of answering if it's not read / acknowledged? What would the motivation for helping be if your answer is blatantly ignored?

AJAX Behaviours -- documentation

Hi!

Can someone please point me to the a place, where Behaviours are explained? I found that some controls have custom behaviours and I found a client side Behaviours class.

I'd like to modify the onkeypress handler of a asp:TextBox control -- is Behaviour the right place to do so?

Thanks,

Miha.

mihav:

Hi!

Can someone please point me to the a place, where Behaviours are explained? I found that some controls have custom behaviours and I found a client side Behaviours class.

It is covered in the docs and explained with code by long time AJAX user Garbin. Hope this helps.

http://ajax.asp.net/docs/ClientReference/Sys.UI/BehaviorClass/default.aspx

http://aspadvice.com/blogs/garbin/archive/2006/01/23/14786.aspx


Thanks. The Garbin's post looks helpful -- the Behaviour class documentation is useless (I found that before) in helping understand what Behavirours are all about.

I'd like to change the the onkeypress event handling of the TextBox control to do a postback on every keypress... I hope behaviours are the right direction to go to?

Thanks,

Miha.


What you want is easier with JavaScript per the thread below, if you choose to use AJAX search Garbin's blog for all related posts and modify the code as needed. Hope this helps.

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


Thanks. I pretty much solved the problem with "ordinary" input type=textbox field and a javascript event handler. I did find out, though, that if I remove the <asp:TextBox> from the page (although I am not using it) the __doPostback updates the whole page, not just the UpdatePanel content. To explain better:

Page has an ordinary text box andasp:TextBox on it. Both text boxes are outside of the update panel. Within an Update panel, there is a AsyncPostBackTrigger, referring to asp:TextBox control (which I amnot using). When I use the ordinary text box, everything works (meaning that the updates only affect update panel). So, if I remove the AsyncPostBackTrigger, the __doPostBack, triggered by ordinary textbox updates the whole page. If I try to wire AsyncPostBackTrigger with ordinary textbox, I get an error

A control with ID 'SearchBox' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
Because there is no control. (it is just markup...).  Is there a way to wire ordinary form field (not asp.net control) with updatepanel?
Miha 


hello.

Triggers are only meant to be used with server side controls. if you have a regular HTML control which starts a postback, then you can try to add the client id of that control to the _asyncPostbackControlsIDs collection maintained by the pagerequestmanager object.


Luis, can you please help me with _asyncPostbackControlsIds collection? Where do I find it? The PageRequestManager does not seem to have it. I've put a script block at the end of the aspx file and I got an undefined value for _asyncPostbackControlsIds.

Aha, I found out it is a typo. But nontheless, the code doesn't work. There must be another way to register this HTML control with pagerequest manager object. The code I tried is:

 var prm = Sys.WebForms.PageRequestManager.getInstance(); prm._asyncPostBackControlIDs.add('SearchBox');
Thanks, Miha.

Sorry. I'm a bit rusty with javascript.

So, I added it to the array.

If I remove the trigger <asp:AsyncPostBackTrigger ControlID="SearchBoxx" EventName="TextChanged" /> from the <triggers> in aspx, the array size decreases to 0, and is 1 after I add the 'SearchBox' HTML control to it. It still doesnot work, because it now refreshes the whole page again. There is something missing to this story. Something to tell the pagerequest manager to only update the updatepanel? The markup generated for the textboxes isidentical in both cases. The only difference on the page is this:

Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1'], ['SearchBoxx'], [], 90);

When there is no <trigger> present, the second parameter is empty. And I tried to add that to a script at the end of the ASPX file, but it still refreshes the whole page...

Aaaaa. I would really like to get rid of the asp:TextBox control, as it is doing nothing on the page...

Miha


hello.

try running this:

<%@. Page Language="C#" AutoEventWireup="true" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

if (ScriptManager1.IsInAsyncPostBack &&
Request.Params["__EVENTTARGET"] == "txt")
{
panel.Update();
}
}
</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 id="Head1" runat="server">
<title>Untitled Page</title>
<script>
function main()
{
// Add Client Code here
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager
<asp:updatepanel runat="server" id="panel" UpdateMode="Conditional">
<ContentTemplate>
panel 1:
<%= DateTime.Now.ToString() %>
</ContentTemplate>
</asp:updatepanel>

<asp:updatepanel runat="server" id="Updatepanel1" UpdateMode="Conditional">
<ContentTemplate>
panel 2:
<%= DateTime.Now.ToString() %>
</ContentTemplate>
</asp:updatepanel>

<input type="text" id="txt" onchange="__doPostBack('txt','');"; />
</form>
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded( function() {
Sys.WebForms.PageRequestManager.getInstance()._asyncPostBackControlClientIDs.push( "txt" );} );
</script>
</body>
</html>


Luis, this is excellent. It works. I'll see what changes I have to make to make my example work and I'll post the solution to my problem (should someone else have the same problem).

Tnx,

Miha.


3 months later, and out of AJAX RC, the solution to this problem was this:

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded( function() {
Sys.WebForms.PageRequestManager.getInstance()._asyncPostBackControlClientIDs.push( "txt" );} );

Thanks again,

Miha.