Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Wednesday, March 28, 2012

Very Basic Static Method Question - SlideShowExtender

I'm working with the SlideShowExtender to show slides from a database. I have everything working as planned, except for a major oversight which I can't figure out how to get around properly. Internally I am housing a static SlideList object which contains all the slides returned from my DAL. Inside my

static AjaxControlTookit.Slide[] GetSlides() method I am copying the SlideList interal objects into the Slide[] object and then returning it. Now for my problem, naturally because my SlideList is static, there is only one copy across each page. When more than one user is on the website at the same time, obviously they are touching the same slideshow data which is causing a lot of problems. What is the correct way to handle this solution? Was I supposed to place the GetSlides() method in a WebService.asmx webservice, or is it ok to keep them as PageMethods and then correctly keep track of the Slides on a per page basis?

I would rather keep the GetSlides() method as a static PageMethod so I don't have to completely refactor the entire project, however I am not sure how I would correctly go about having Slides and then accessing them within my static methods. I realize this is a very elementary problem, and I feel awfully silly for not knowing the answer!

THanks!

Hi,

Your question is how to return different slides upon different requests, isn't it?

Well, you may pass a parameter (contextKey) into the GetSlides method, and use it to filter some slides.

For example, let's say you plan to filter the slides according to the userName of the one is browsing the page, you assign current user name in Page_Load.

protected void Page_Load(object sender, EventArgs e)
{
this.slideshowextend1.ContextKey = currentUserName;
}

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static AjaxControlToolkit.Slide[] GetSlides(string contextKey)
{ // return a slide array according to contextKey
}

Hope this helps.

Monday, March 26, 2012

vista, ajax 1.0 release and web application projects - no intellisense

Hi,

Is anyone else having problems getting intellisense working with the 1.0 release and web appliation projects?

I should add this is on vista and vs2005 sp1 is not installed

Sometimes it seems to be available after switching from design view back to source but not always, also it seems to be worse where a master/child page is used - often when I drop an update panel onto the source its id does not get auto populated? and no intellisense is available?

Any advice welcome

thanks

Richard

You need SP1, and there is another update for vista that you will need. Also, you may need to delete some user data for visual studio.

Visual Studio 2005 Installation Question?

Greetings. I'm not exactly sure where to post this question so I apologize if this is the wrong place.

I've just started working with ASP.net AJAX and the Toolkit. I have had success getting my environment all setup and have successfully created a page with a slideshowextender.

Thing is, I must not have done something right because even though everything appears to work, I get the red squiggly line under anything AJAX or Tooklit related in source mode in Visual Studio 2005 Pro. I basically followed the instructions on setting up the environment on the Toolkit demo page after installing the AJAX extensions. I then followed the instructions in some of the Toolkit demonstration videos to get everything else working.

Just wondering if there's a step I missed in order to make VS2005 understand what all the new controls are. Any tips would be appreciated.

Jim Sparks

Hi Jsparks,

jsparks:

Thing is, I must not have done something right because even though everything appears to work,

Do you mean the SlideShowExtender works as your expect?

If not, we suggest that you should check yourweb.config settings. Also you should check whether the ASP.NET 2.0 Ajax Extensions V1.0 and Ajax Control Toolkit works properly or not.

I hope this help.

Best regards,

Jonathan

Visual Studio wont recognize some AJAX components when there is a master page

This is a really weird thing. I have installed AJAX and the toolkits and the validators, and everything was working fine. Then, suddenly, Visual Studio won't let me switch to design view b/c the script Manager and the update panels are now "not known elements," and so are all the labels, panels, dropdownlists, etc inside the update panels. Oddly enough, the components in the AJAX toolkit are still recognized just fine. when this problem first started happening, i would click over to the master page and click back to the aspx page and everything was fine. Now that doesn't even work. And the craziest part is that the web site runs just fine when I debug it, AJAX functionality and all!

I would have blamed this on the way I installed the AJAX framework, but this only happens on pages with master pages.

Does anyone have any experience with this? Or is it just my machine? No one else here at work is having this problem, but I am the only one who is really using AJAX.

Any ideas would be welcome. Thanks in advance

Hi,

As far as I know, the error message indicates the issue is related to permission. It seems your ASP.NET applications run in partial trust. This is configured through the <trust level="xxx" /> setting in web.config or machine.config. Please change the "xxx" to medium and try again to figure out whether the problem still occurs.

Best Regards


Thanks for your suggestion. I don't even have any trust level permissions in my web.config files, so I am assuming that the problem is in my machine.config file. But before I go messing around in there, I would like to try to override it in the web.config. This is what I have in my web.config. But the error I am getting on the page declaration of the default.aspx page is "Unable to read the security policy file for trust level 'medium'." Where are the policy files located?

<location allowOverride="false">
<system.web>
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
<trustLevel name="High" policyFile="web_hightrust.config"/>
<trustLevel name="Medium" policyFile="web_mediumtrust.config"/>
<trustLevel name="Low" policyFile="web_lowtrust.config"/>
<trustLevel name="Minimal" policyFile="web_minimaltrust.config"/>
</securityPolicy>
<trust level="medium" originUrl=""/>
</system.web>
</location>

VS 2005/MS Ajax Beta Application no longer runs on Live server but does in Dev. Help!

I have just migrated from Atlas to MS Ajax Beta and after a lot of hassle to get the application working I decided to publish to our test web server. When I go to the URL for our test server all I get is a blank page but the IE progress bar (the bar at the bottom that show the page loading status) just flickers like crazy. It works fine on my dev machine but as soon as I publish it, no joy!

I really need some help on this as I don't really have a clue and I don't really fancy having to roll back to Atlas just to get this to work live.

Cheers,

FF

Ignore me, I'm stupid!!

I hadn't checked if the extensions were installed on the server!! DOH!!!


hello.

well, you must install ajax extensions on the live server and configure your site to use asp.net 2.0. have you done that already?

Want to call a javascript function from code behind

Hi.

I am trying to call a javascript function on button click, buttton is present in update panel. It is not working.

On button click event handler i m writing the following code

Response.Write("<script>functionname();</script>");

I have added script reference in script manager and given the path.

Response.Write("<script>functionname();</script>") --> this works if button is outside update panel.

Help me...

Why not try placing your javascript function name in the button's OnClientClick parameter? That way it calls it directly without requiring a post back...

OnClientClick = "functionname();"


PhunkNugget:

If you do that, which runs first, the javascript in the client or the

click event code in the code behind? may be related, so it's

important to know..I also need to invoke a modal popup

extender from code in a codebehind, not from a click event..

I'm watching this thread closely.. Geeked

Thanks in advance..


The OnClientClick runs first.


Kanwar,

You can't use Response.Write() inside an update panel. It conflicts with the ajax somehow (very annoying). You can attach the script to your button's onclick event in page load such as the following:

string myString="<script language='Javascript'>\n";

myString+="function fuctionname()\n";

myString+="{\n";

myString+="whatever your function does...\n";

myString+=

"}\n";myString+="</script>\n";

Page.RegisterClientScriptBlock(

"MYFUNCTION", myString);

btnMyButton.Attributes.Add(

"onClick","functionname();");

Then when you click on the MyButton, the javascript function will be called.

Saturday, March 24, 2012

Want to use something other than a xmldocument to feed the cascading dropdown list

I'm starting to use the toolkit and the first control I'm working on is the cascading dropdown list. I'm messing with the web service right now. The example uses an xmldocument for the source of the data. My data is already being returned in the form of a list. Can I make that work or do I have to turn my data into an xmldocument? Hopefully not.

Thanks for the help

Hi,

Yes, you can make this work. All you really need to do is implement a web method that returns an array of CascadingDropDownNameValue objects. Check outhttp://ajax.asp.net/ajaxtoolkit/Walkthrough/CCDWithDB.aspx for an example. Just map your list of items to CascadingDRopDownNameValue objects and you should be good.

Thanks,
Ted

Warning: Unable to update auto-refresh reference microsoft.web.atlas.dll

We are 2 developers working on a web application and we started to use ASP.Net Ajax (Atlas). We added the the toolkit and asp.net ajax to the toolbox in visual studio 2005 and we added the 2 dlls to our bin directory in the project. Everytime we move the project from one machine to the other we recieve the following warnings

Warning: Unable to update auto-refresh reference 'microsoft.web.atlas.dll'. Can not find assembly 'D:\ZPrograms3\DotNetFrameworkEnhancements\AspNetAjax (Atlas)\AtlasControlToolkit\SampleWebSite\Bin\Microsoft.Web.Atlas.dll'.

Warning: Unable to update auto-refresh reference 'atlascontroltoolkit.dll'. Can not find assembly 'D:\ZPrograms3\DotNetFrameworkEnhancements\AspNetAjax (Atlas)\AtlasControlToolkit\SampleWebSite\Bin\AtlasControlToolkit.dll'.

Should we put the ASP.Net stuff in a folder on the C: drive in a ASP.Net folder on both machines. What I don;t understand is why we have to do that if we have the dlls in our bin folder in the project. Can anyone clarify?

Newbie

hello

i think this is nothing to worry about. the problem is that VS is trying to get a new dll when you compile and when you've moved the project to another machine, you've just lost that reference (probably you don't have the toolkit on the other machine or it's placed in a different folder). so this shouldn't take your sleep :D


But what is the solution?

Set a new reference?

WCF ASP.NET Service not working - what am I missing

Hello. This is a simple question, so please take a look.

I am using Orcas Beta2 and I created a new Solution. In there added a Web Application Project. In the project I created an Ajax enabled WCF service. When I call the service from JavaScript I get this error: Service1 is not defined. What am I missing? Here is the very simple code. Thanks!

default.aspx:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._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>
<script type="text/javascript">
function Hello() {
WebApplication1.Service1.HelloWorld(onComplete, onTimeout);
}
function onComplete(result) {
alert(result);
}
function onTimeout(result) {
alert("Timed out!");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<input type="button" value="Call Hello" onclick="Hello()" />
</div>
</form>
</body>
</html>

namespace WebApplication1
{
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public string HelloWorld()
{
return "helooo";
}
}
}

code for the service:

namespace WebApplication1
{
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public string HelloWorld()
{
return "helooo";
}
}
}

web.config (this is generated by VS2008 and i did not modify it):

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" compilerOptions="/warnaserror-" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
</compiler>
</compilers>
</system.codedom>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebApplication1.Service1AspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="WebApplication1.Service1">
<endpoint address="" behaviorConfiguration="WebApplication1.Service1AspNetAjaxBehavior" binding="webHttpBinding" contract="WebApplication1.Service1"/>
</service>
</services>
</system.serviceModel>
</configuration>

Thanks!

Checkout the following post:
http://odetocode.com/Blogs/scott/archive/2007/07/30/11171.aspx


Yep, I'm guessing this is what you're missing. Afraid you can't get away with just .html as the client. You'll have to create an .aspx page.

Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>


Thanks Kazi,

I tried this and ran into other problems. See http://forums.asp.net/p/1170276/1956960.aspx#1956960

I thought that the default out of the box experience should be easy. It seems that it is not and one needs to fully understand te WCF model before getting anything to work. And WCF is a big monster to learn just to expose a simple REST service.


Jonathan,

Sorry for cutting and pasting only part of the aspx file. i updated the post and included all of the aspx file. Yes, i am using an aspx file and not an html file. Otherwise it would not compile. I tried adding the Factory to the svc file but it did not work for other reasons. It would be nice if someone, (hello Microsoft! :)) would post steps to create a simple service and how to consume it via an aspx page. This was dead simple in asmx, but wcf has just too many knobs and it seems that detailed knowledge of wcf is required to get this to work.


Thanks!

Wednesday, March 21, 2012

web service "is not defined"

I recently upgraded to Ajax 1.0 from ATLAS and now my web services are not working. My service references are not working, I get the "[namespace] is not defined" JS error. However, i can see that the [webservice].asmx/JSDEBUG scripts are being referenced fine. I assume the problem is with my configuration; here is the (important) contents of my Web.Config:

12<configuration>3<configSections>4<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">5<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">6<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>7<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">8<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />9<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />10<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />11</sectionGroup>12</sectionGroup>13</sectionGroup>14</configSections>1516<system.web>17<pages enableEventValidation="false" viewStateEncryptionMode="Never">18<controls>19<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>20</controls>21</pages>2223<httpHandlers>24<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>25<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>26<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>27<add verb="*" path="CaptchaImage.aspx" type="JSM.OpenFrame.HttpHandlers.CaptchaImageHandler"/>28<remove verb="*" path="*.asmx"/>29</httpHandlers>3031<httpModules>32<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>33</httpModules>3435<compilation debug="true">36<assemblies>37<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>38<add assembly="Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>39<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>40<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>41</assemblies>42</compilation>4344<authentication mode="Windows"/>4546<customErrors mode="Off" defaultRedirect="GenericErrorPage.htm">47<error statusCode="403" redirect="NoAccess.htm"/>48<error statusCode="404" redirect="FileNotFound.htm"/>49</customErrors>50</system.web>5152<system.web.extensions>53<scripting>54<scriptResourceHandler enableCompression="true" enableCaching="true" />55</scripting>56</system.web.extensions>5758<system.webServer>59<validation validateIntegratedModeConfiguration="false"/>6061<modules>62<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>63</modules>6465<handlers>66<remove name="WebServiceHandlerFactory-Integrated" />67<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>68<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>69<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />70</handlers>71</system.webServer>72</configuration>

Is your webservice flagged with the [ScriptService] attribute? If not, there's your problem. the new version uses that attribute to decide which services need to be serialized as JS objects.


Thanks, I didn't know that. I marked my service with [ScriptService] and also marked a method with [ScriptMethod] and I still get the "is not defined" error. Anything else I'm missing?
Might be the fact that you're removing your asmx handler after you add it.. . Put the <remove> as the first entry of the HttpHandlers section and see if that helps.
Moved that but am still getting the JS error. Thanks.

HI joshmccullough,

I think you have to provide us with more information:

What assembly is referenced in you project: System.web.extensions?

Paste your code of you webservice and also the webpage that's calling it. Thanks in advance!

Regards,


I am using a master page. I have a validation control which uses a webservice (see code below); this is where the service reference is added to the page. Note that the RenderJavaScript method is called during PreRender. There is more code involved but short of posting my whole project, here is the important stuff...

Web Service:

1"C#" Class="JSM.OpenFrame.WebServices.GenericLiveValidation" %>2using System;3using System.Web;4using System.Collections;5using System.Web.Services;6using System.Web.Services.Protocols;7using System.Web.Script.Services;8using JSM.OpenFrame.Common;9using JSM.OpenFrame.DataObjects;10using JSM.OpenFrame.Util;1112namespace JSM.OpenFrame.WebServices13{14 [WebService(Namespace ="JSM.OpenFrame.WebServices")]15 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]16 [ScriptService]17public class GenericLiveValidation : System.Web.Services.WebService18 {19 [WebMethod]20public LiveValidationResponse ValidateEmailAddress(string emailAddress)21 {22if (!RegExUtil.ValidateEmailAddress(emailAddress))23return new LiveValidationResponse(false,"The email address field is invalid. Email addresses must be in the form \"user@.host.com\".");24else if (ContactUtil.DoesEmailAddressExist(emailAddress))25return new LiveValidationResponse(false,"This email address is already in use. Please try another.");26else27 return new LiveValidationResponse(true);28 }2930 [WebMethod]31 [ScriptMethod]32public LiveValidationResponse ValidatePassword(string username,string password)33 {34 JSM.OpenFrame.Util.LoginUtil.LoginResult result = LoginUtil.ProcessLogin(username, password);3536if (result == LoginUtil.LoginResult.BadPassword)37return new LiveValidationResponse(false,"The password you entered is not correct.");3839return new LiveValidationResponse(true);40 }41 }42}

Page:

1<%@. Page Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="True" Inherits="MyAccount.AccountInfo" Title="Change Password" Codebehind="AccountInfo.aspx.cs" %>2<%@. MasterType VirtualPath="~/Main.master" %>3<%@. Register TagPrefix="WebControls" Assembly="JSM.OpenFrame" Namespace="JSM.OpenFrame.WebControls" %>4<%@. Register TagPrefix="Validation" Assembly="JSM.OpenFrame" Namespace="JSM.OpenFrame.WebControls.Validation" %>56<asp:Content ID="Content" ContentPlaceHolderID="_contentPlaceHolder" Runat="Server">7 <table cellspacing="1" cellpadding="2" class="Form_Table">8 <tbody>9 <tr>10 <td class="Form_Table_Label">Current Password:</td>11 <td class="Form_Table_Input" style="width: 250px;">12 <asp:TextBox ID="currentPassword" runat="server" CssClass="Form_Textbox_Wide" TextMode="Password" />13 </td>14 </tr>15 <tr>16 <td colspan="2" class="Form_Table_Seperator"></td>17 </tr>18 <tr>19 <td class="Form_Table_Label">New Password:</td>20 <td class="Form_Table_Input">21 <asp:TextBox ID="newPassword1" runat="server" CssClass="Form_Textbox_Wide" TextMode="Password" />22 </td>23 </tr>24 <tr>25 <td class="Form_Table_Label">New Password (again):</td>26 <td class="Form_Table_Input">27 <asp:TextBox ID="newPassword2" runat="server" CssClass="Form_Textbox_Wide" TextMode="Password" />28 </td>29 </tr>30 <tr>31 <td colspan="2" class="Form_Table_ButtonRow">32 <asp:Button ID="saveButton" runat="server" Text="Save" CssClass="Form_Button_Footer" />33 </td>34 </tr>35 </tbody>36 </table>37 <Validation:FormValidator runat="server">38 <Validation:LiveValidator runat="server" Required="true" TargetControlID="currentPassword" ServicePath="~/Services/GenericLiveValidation.asmx" ServiceMethod="JSM.OpenFrame.WebServices.GenericLiveValidation.ValidatePassword" />39 </Validation:FormValidator>40</asp:Content>

LiveValidator control:

1using System;2using System.Collections.Generic;3using System.Text;4using System.Web.UI.WebControls;5using System.Collections.Specialized;6using System.Web.UI;7using JSM.OpenFrame.Util;89namespace JSM.OpenFrame.WebControls.Validation10{11public class LiveValidator : ValidatorBase12 {13private string _servicePath;14private string _serviceMethod;1516public string ServicePath17 {18get {return _servicePath; }19set { _servicePath =value; }20 }2122public string ServiceMethod23 {24get {return _serviceMethod; }25set { _serviceMethod =value; }26 }2728protected override void RenderJavaScript()29 {30 ServiceReference service =new ServiceReference();31 WebControl control = (WebControl)CommonUtil.FindControlRecursive(_targetControlID,this.Page.Controls);32 StringBuilder script =new StringBuilder();3334 service.Path = _servicePath;35 ((BasePage)this.Page).AppendServiceReference(service);3637this.Page.ClientScript.RegisterClientScriptResource(this.GetType(),"JSM.OpenFrame.Resources.LiveValidator.js");38 control.Attributes.Add("onblur",this.ClientID +".Validate();");3940 script.Append("<script language=\"JavaScript\">\n");41 script.Append("\tvar " +this.ClientID +" = new LV_Object(\"" + this.ClientID + "\", document.getElementById(\"" + control.ClientID + "\"), \"" + _serviceMethod + "\", " + _required.ToString().ToLower() +");\n\n");42 script.Append("</script>");4344this.Page.ClientScript.RegisterStartupScript(this.GetType(),"LV_" +this.ClientID, script.ToString());45 }46 }47}

I was having this problem too when working using the 'web application' model.

If your project is called 'AJAXEnabledWebApplication1', your service has the namespace 'WebService' and the method is 'HelloWorld()' then you need to reference it using the full project namespace even if the aspx file is in the same folder as the asmx file:

AJAXEnabledWebApplication1.WebService.HelloWorld()

Annoyingly it works as expected (ie simply WebService.HelloWorld() works) when using the 'web site' model.

Any idea why this is the case?

Have fun
Finn


Ok, another problem I see is that you're using Page.ClientScript, which I believe is deprecated. The current way to make the reference should be:

ScriptManager sm = ScriptManager.GetCurrent(Page);ScriptReference script =new ScriptReference(pathToScript);sm.Scripts.Add(script);ServiceReference service =new ServiceReference(pathToService);sm.Services.Add(service);

For dnamically built js (sctrings like you have) it should be done w/ the static members of ScriptManager, eg.:

ScriptManager.RegisterClientScriptBlock(Page, type, key, script, addTags);

Hope that helps...


I am using a WebApplication project. I changed the code to use the ScriptManager instead. Still getting the same error. How do you figure out what the namespace should be for the webservice? Maybe I am doing that part wrong?

I don't actually see where you're calling the webservice at all, now that I'm looking at your js. As an aside, you really should use an embedded resource file instead of hardcoding the js like that, it' makes it a lto easier to debug and maintain.

Anyway, in theory your call should look something like this:

JSM.OpenFrame.WebServices.LiveValidator.ValidateEmailAddress(args,OnSuccess);where OnSuccessis another javascript function that fires off when that webservice returns without an errror.

I acutally am using embedded resources, those few lines just create the object (the real code is in the resource). That is what my call looks like. By the way, the full error message is "JSM is not defined" so its not even getting anywhere in the namespace...

If you take a look at the javascript returned from the webservice the first line will look something like this:

Type.registerNamespace('AJAXEnabledWebApplication1');

Try tagging AJAXEnabledWebApplication1. (ie the project root namespace that's trying to be registered by the JS) at the start of your function's namespace.

As the namespace registration works in a web project but not a web application I'm wondering what I'm missing here - or is it a bug?


Have fun
Finn


Ok, it is working now. Turns out I also had a compile error in the WebService (UGH). Even if I did not, it would not have worked since I did not marked the WS with [ScriptService]. Thanks for all the help, I am good to go...for now.