Showing posts with label following. Show all posts
Showing posts with label following. Show all posts

Wednesday, March 28, 2012

Why javascript function can not be found in Firefox with a AJAX page?

Following page works fine with IE. When click on Html button, the javascript function is called and works fine.

But when run the same page in Firefox, it reported that the error as below:

myFunction is not defined

onclick(click clientX=0, clientY=0)

What's the possible reason and how to solve it?

--the page code:the page also include some Ajax toolkit and the code for that is omitted.

<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false" Codebehind="workshop.aspx.vb" Inherits="my.workshop" %>
<!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>Workshop Registeration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<link href="http://links.10026.com/?link=StyleSheet1.css" rel="stylesheet" type="text/css" />
<script type="text/jscript" language="javascript" >

function reset(){
document.workshop.reset();
}

function myFunction() {
alert("test");
}

</script
</head>
<body class="page">
<form id="workshop" runat="server">
<asp:ScriptManager runat="server" EnableScriptGlobalization="true" ID="MasterScriptManager"
EnablePartialRendering="true" ScriptMode="Release" AsyncPostBackTimeout="72000">
</asp:ScriptManager>
<div>
<table border="1" cellpadding="0" cellspacing="0">
<tr class="namearea">
<td align="center" class="dataarea">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="right" style="width: 50%">
<input class="jsbutton" onclick="javascript:myFunction();" type="button"
value="Button1" />
</td>
<td align="left" style="width: 50%; background-color: White;">
<br />
<asp:PlaceHolder ID="plcmyHolder" runat="server"></asp:PlaceHolder>
<br />
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Change the script type from text/jscript to text/javascript and it'll work.

Why my web services cant accept parameter?

When my javascript call the echoString(s) in the following code, it return nothing

<%@dotnet.itags.org. WebService Language="C#" Class="WebService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {

[WebMethod]
public string echoString(string s) {
return s;
}

}

The strange things are my .NET program works fine with the code above and my javascript client program doesn't work with the code above but works fine with other people's web services. EX:

http://www.mssoapinterop.org/asmx/simple.asmx?op=echoString

What is wrong with my code? Thank you!!!!!!!!!

asdpai:

what is wrong with my code?

nothing, code is correct. Decorate youre WebService with theSystem.Web.Script.Services.ScriptService() and the WebMethode with the ScriptMethod() attribute eg.

<%@. WebService Language="C#" Class="WebService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
usingSystem.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService()]
public class WebService : System.Web.Services.WebService {

[ScriptMethode()]
[WebMethod]
public string echoString(string s) {
return s;
}

}

Hope that coul help.

Why the value always is false?

Following is my codes. No matter I login or not,the userLoggedIn always be false. Why?

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" Codebehind="WebFormTest.aspx.cs" Inherits="EdtungWeb.WebFormTest" %><!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 language="javascript" type="text/javascript">
// <!CDATA[ function Test() { debugger var userLoggedIn = Sys.Services.AuthenticationService.get_isLoggedIn(); } // ]]> </script
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="Test()" />
<asp:Login ID="Login1" runat="server">
</asp:Login>
<asp:LoginStatus ID="LoginStatus1" runat="server" />
</form>
</body>
</html>

and the loginstatus is retrieving the right information?


Yes, it is, the loginstatus is retrieving the rightinformation.

Many thanks for your replying.

Unless you use the AuthenticationService to Login the user it will remain false. One hack might be to inject the following line in your pages from the server side when you are sure the user is logged in.
Sys.Services.AuthenticationService._authenticated = true;

I see.

Many thanks for your replying.


Would you mind marking that as answer.

Sorry for that.

Many thanks for your remind.

Monday, March 26, 2012

window.debug has no properties since upgrade from RC to RTM

Hi!

Since I upgraded from AJAX RC to AJAX RTM I get following erros:

'window.debug.isDebug' is null or not an object -> IE7
window.debug has no properties -> Firefox
if (!window.debug.isDebug) { ...ScriptResource.axd (line 107)

What can be wrong?

Thanks for your help

Martin

The problem is fixed now. It seems that the control toolkit was not up to date within the project although I used "Rebuild Solution" and followed the release notes.

Wednesday, March 21, 2012

Wrong URL for Webservice

Hello

I've a Problem with Webservice Calls and/or Scripttags (not sure)
In the default.aspx I've the following Script declaration:

<asp:ScriptManager ID="scriptManager" runat="server" ScriptMode="debug">
<services>
<asp:servicereference path="~/webservices/myWebservice.asmx" />
<services>
<asp:ScriptManager /
Some times the Service is called with this URL: http://www.mySite.com/webservices/myWebservice.asmx/webservices.myWebservice
The extra "/webservices.myWebservice" is wrong and the Page could not be found.

I'm sure the wrong URL is generated from Javascript (in one of the JS-Files from the Framework) when executing the functions in myWebservice or from the generated HTML-Code from the Default.aspx Page (something like <script language="javascript" src="http://pics.10026.com/?src=http://www.mySite.com/webservices/myWebservice.asmx/webservices.myWebservice />)

Any Ideas how to solve this error? Are there any Updates for the AJAX-Framework?

Your webservice is only like thishttp://www.mySite.com/webservices/myWebservice.asmx

there is no need for webservices.myWebservice /

try it


This is the normal way a webservice method is called. There is nothing wrong in it.

The method name is appended to the webservice url

For example, if you are calling a method called method1 on webservice.asmx, the url will look like

http://.../webservice.asmx/method1


But why do I get errors like the following:

Ausnahmeinformationen:
Ausnahmetyp: InvalidOperationException
Ausnahmemeldung:Request format is unrecognized for URL unexpectedly ending in '/webservices.myWebservice'.

Anforderungsinformationen:
Anforderungs-URL:http://www.mySite.ch/webservices/myWebservice.asmx/webservices.myWebservice
Anforderungspfad: /webservices/myWebservice.asmx/webservices.myWebservice

Threadinformationen:
Thread-ID: 1
Stapelüberwachung: bei System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
bei System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
bei System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
bei System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
bei System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
bei System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

If I try to call the webservice directly, I get the same error in Browser.


Check if you have this in the web.config. I have seen this to cause this error

<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>


Thank you for the tipp. That code is not in the web.conf. I'll try if it helps.


I would guess that your web.config is missing these entries:

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

xhtmlConformance and Dissappearing Script Blocks

Hello all,

When running an ASP.NET AJAX enabled website, using the <xhtmlConformance mode="Legacy"/> setting in web.config, the following script block is missing from the html source...

<script type="text/javascript">
<!--
var theForm = document.forms['_Form'];
if (!theForm) {
theForm = document._Form;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>


<script src="http://pics.10026.com/?src=http://forums.asp.net/WebResource.axd?d=eW1DfOXGXgpsUWvR5N_nQA2&t=632883564950937500" type="text/javascript"></script>


<script src="http://pics.10026.com/?src=http://forums.asp.net/ScriptResource.axd?d=t6b0XUF5KALdJUwU0jqPT4TSBLSwGNG8Xz7w6ZwsYjFMFEynUA2ntBX4Dw87QRWGTU5E4WnEFzydFLnRmOOay11AM18Ci2X-gyhkYo3Ba8E1&t=633052376131250000" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=http://forums.asp.net/ScriptResource.axd?d=t6b0XUF5KALdJUwU0jqPT4TSBLSwGNG8Xz7w6ZwsYjFMFEynUA2ntBX4Dw87QRWGTU5E4WnEFzydFLnRmOOay7blg0HNmWo42yHqnKI0itTLd1_U0ZtQoPW4oZyWkDwL0&t=633052376131250000" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=ws/AjaxUploadService.asmx/jsdebug" type="text/javascript"></script>

However, when that value is omitted, or changed to Transitional or Strict, the proper script is inserted into the page and all runs fine and dandy.

Pretty nasty bug there fellas!

"text/javascript">'_Form'];if (!theForm) { theForm = document._Form;}function __doPostBack(eventTarget, eventArgument) {if (!theForm.onsubmit || (theForm.onsubmit() !=false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); }}// -->

andrew_,

Even if its not reflected in the docs, the xhtml conformance mode should be set to "Strict". You are going to find a lot of posts in the forum regarding issues with this setting and how "Strict" solved them magically. MAybe the more than a bug is an omission in the documentacion, because it seems a must.

Cheers,

Juan

XmlDocument parameter error

I have the following webservice function definition:

[WebMethod(EnableSession =true)]

[ScriptMethod(ResponseFormat =ResponseFormat.Xml)]

publicXmlDocument requestXML(XmlDocument requestXML)

I am trying to pass the XmlDocument parameter from JavaScript on an Ajax enabled web page:

<scripttype="text/javascript">

function newDocument(text)

{

if (typeof DOMParser !="undefined")

{

return (new DOMParser( )).parseFromString(text,"application/xml");

}

else

{

var doc =new ActiveXObject("MSXML2.DOMDocument");

doc.loadXML(text);

return doc;

}

}

// This function calls the Web Service method.

function request()

{

var entryElem = document.getElementById("entry");var entryText = newDocument("<loginOwner><question>"+entryElem.value+"</question><UserID>visitor</UserID><OwnerName>anonymous</OwnerName></loginOwner>");

improxy.requestXML(entryText, onOK);

}

function onOK(resultXML)

{

alert(resultXML.xml);

}

</script>

I am getting an error: "Microsoft JScript runtime error: Object doesn't support this action". In the debugger, this error occurs in the function: "Sys.Serialization.JavaScriptSerializer._serializeWithBuilder".

Isn't the XmlDocument type supported as a parameter in Ajax?

Thanks,

Eyal

The Client Side document is not compatible with the server side object. You can simply send the xml as plain string.


1. The return value is also a server side XmlDocument and this is translated correctly to the client side object. Can't this be done for a parameter?

2. If I send the XML as string, the webservice complains about wrong data types. Is there another way to tell the server to handle this string as XML?


Hi

I have tested that sending the XML as string to webservice,and it works.

Try this:

Default.aspx

<%@. 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">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script type="text/javascript">
// function newDocument(text)
// {
// if (typeof DOMParser != "undefined")
// {
// return (new DOMParser( )).parseFromString(text, "application/xml");
// }
// else
// {
// var doc = new ActiveXObject("MSXML2.DOMDocument");
// doc.loadXML(text);
// return doc;
// }
// }

// This function calls the Web Service method.
function request()
{
// var entryElem = document.getElementById("entry");
var entryText = "<loginOwner><question>entryElem</question><UserID>visitor</UserID><OwnerName>anonymous</OwnerName></loginOwner>";
// throw "";
Samples.AspNet.WebService.GetXmlDocument(entryText, onOK);
}

function onOK(result)
{
// Page element to display feedback.
var RsltElem = document.getElementById("ResultId");

var readResult;
if (document.all)
readResult = result.documentElement.firstChild.text;
else
// Firefox
readResult = result.documentElement.firstChild.textContent;
RsltElem.innerHTML = "XmlDocument content: " + readResult;
}
</script>

</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="http://localhost/AJAXEnabledWebSite/WebService.asmx" />
</Services>
</asp:ScriptManager>
<div>
<button id="Button2" onclick="request(); return false;">
Server Time</button>
<span id="ResultId"></span>
</div>
</form>
</body>
</html>

WebService.asmx

<%@. WebService Language="C#" Class="Samples.AspNet.WebService" %>

using System;
using System.Web;
using System.Xml;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

namespace Samples.AspNet
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService() { }

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlNode GetXmlDocument(string requestXML)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(requestXML);
return xmlDoc;
}
}
}

Best Regards


More information about this topic:

Passing an XML instance to a Web Service Method :http://objectsharp.com/cs/blogs/matt/archive/2004/10/30/989.aspx

Passing XmlDocument to .Net Webservice from IE client :http://www.dotnet247.com/247reference/msgs/6/32784.aspx


Thank you. I know passing a string works. My web service expects an XmlDocument parameter, not a string.


I tried the links. None of them shows how to pass an XmlDocument with Ajax. Only directly with XMLHTTP.

XMLHttpExecutor

Hi guys,

I have noticed the following code in the abort function of the Sys.Net.XMLHttpExecutor class:

var a=this._webRequest._get_eventHandlerList().getHandler("completed");
if(a)
a(this,Sys.EventArgs.Empty)

The documentation states that the completed event of the WebRequestManager is raised when the request is completed, timed out or aborted.

Maybe the code should be:

a._webRequest.completed(Sys.EventArgs.Empty);

like in the case when the request is completed or timed out.

Is thig a bug or a feature?

Bogdan

The executor sets the Web request state to aborted. This means that the XMLHttpExecutor Class instance's started Property and aborted Property methods both return true.
Next the WebRequestManager Class instance calls the completed event handler on the associated request object.
After the abort method is called, the state of the response returned by the executor's methods is undefined.
You can call the abort method multiple times. However, the second and subsequent calls are not processed. The completed event handler is raised only once.
You get an exception if you call the abort method before you call the executeRequest Method method.

The unique document?about?Sys.Net.XMLHttpExecutor we can use is from?here?-?http://ajax.asp.net/docs/ClientReference/Sys.Net/XmlHttpExecutorClass/default.aspx
Try to take a look at it and get some ideas from it.

Thank you for your response! Perhaps I didn't make it clear enough .. I agree on what you said about the abort method and what happens if it is called multiple times but my concerns are related to the completedRequest event of the WebRequestManager that is no longer raised in this case.

When a request is timed out the _onTimeout event handler is called and thus the WebRequest's completed event is called:

this._onTimeout=function(){
if(!a._responseAvailable){
a._clearTimer();
a._timedOut=true;
a._xmlHttpRequest.onreadystatechange=Function.emptyMethod;
a._xmlHttpRequest.abort();
a._webRequest.completed(Sys.EventArgs.Empty);
a._xmlHttpRequest=null
}
}

By Calling the completed method of the underlying WebRequest the completedRequest event of the WebRequestManager and also the completed event of the WebRequest are raised and all the registered event handlers notified.

Likewise in the XMLHttpExecutor class when the request completes the same completed method of the WebRequest is invoked:

this._onReadyStateChange=function(){
if(a._xmlHttpRequest.readyState===4){
a._clearTimer();
a._responseAvailable=true;
a._webRequest.completed(Sys.EventArgs.Empty);
if(a._xmlHttpRequest!=null){
a._xmlHttpRequest.onreadystatechange=Function.emptyMethod;
a._xmlHttpRequest=null
}
}
};

Like in the first case the completedRequest event is also raised.

When the request is aborted the completedRequest is not raised any more :

abort:function(){
if(this._aborted||this._responseAvailable||this._timedOut)
return;
this._aborted=true;
this._clearTimer();
if(this._xmlHttpRequest&&!this._responseAvailable){
this._xmlHttpRequest.onreadystatechange=Function.emptyMethod;
this._xmlHttpRequest.abort();
this._xmlHttpRequest=null;
var a=this._webRequest._get_eventHandlerList().getHandler("completed");
if(a)
a(this,Sys.EventArgs.Empty)
}
}
};

What do you think about the above mentioned? Do they represent the correct behavior?

Thanks in advance,

Bogdan


Phew !!

Check out this post:

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

They have finally realized the bug.. Probably it'll be fixed in the RTM release..

Bogdan