Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Wednesday, March 28, 2012

ASP.NET AJAX PageMethods

I would like to call a server side method from javascript, and have read that this is where PageMethods comes into the picture.

I would like to call my method when a Virtual Earth map onLoad event has fired.

I have problems with PageMethods as the method called serverside has to be shared and therefore i cannot reference my controls.

Is there other options ?

You can't access page controls in a page method, because a page method request doesn't transmit ViewState or run through the page life-cycle to create the controls.

If you really need to reference the controls, you canuse an UpdatePanel and __doPostBack to trigger a partial postback (which does allow you to reference the controls).


You can also pass clientside state through parameters if needed.

Saturday, March 24, 2012

asp.net 2.0 div in call page

Hi everyone;

I try a div in call the any page but with ie does not work, return this error message "Unknow Runtime Error".

However try with firefox in its work but this browser the return error"System.Web.HttpException: The state information is invalid for this page and might be corrupted.";

What is the problem? Everyone thanks.

your description of the problem is blur. please be more specific and give more details like code sample.


Hi,

this source with call the div in aspx file.

function ajax()
{
var xmlAjax = false;

if(window.ActiveXObject)
{
try
{
xmlAjax = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(err)
{
try
{
xmlAjax = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(err)
{
alert(err)
}
}
}
else if(window.XMLHttpRequest)
{
try
{
xmlAjax = new XMLHttpRequest();
}
catch(err)
{
alert(err);
}
}
else
{
alert('Browser?n?z ajax desteklemiyor');
}
return xmlAjax;
}

var xmlHttp = ajax();

function Loading(url,dvId)
{
if(xmlHttp)
{
xmlHttp.onreadystatechange=function(){
LoadPage(dvId);
}
xmlHttp.open('GET',url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-9")
xmlHttp.send(null);

}
}

function LoadPage(dvId)
{
switch(xmlHttp.readyState)
{
case 3:
document.getElementById(dvId).innerHTML = "Loading";
break;
case 4:
document.getElementById(dvId).innerHTML = xmlHttp.responseText;
break;
}
}

this source run ie, not load the div in aspx page and return error "Unknow Runtime Error";

however this source run firefox, aspx page load but its page in the click the asp:button return error "

The state information is invalid for this page and might be corrupted.

Description:Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.

Exception Details:System.Web.HttpException: The state information is invalid for this page and might be corrupted."

What is the problem ?

Save My God


Hi

Try this:

function newXMLHttpRequest()
{
var xmlreq = false;
if (window.XMLHttpRequest)
{
xmlreq = new XMLHttpRequest();
}else if (window.ActiveXObject)
{
try {
xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
try {
xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
}
}
}
return xmlreq;
}

Best Regards


hi Jin;

Thanks this source but not works, again return this error "Unknow runtime error",

however firefox in works. I dont understant. stupid problem.

Wednesday, March 21, 2012

ASMX Web service

Hi all,

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

Thanks

Regards

Stephanie

Never tryed, is this going to work?

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


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

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

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


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

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

Hope that helps,
-Hao


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

I have tried that without any success.

Xiyuan Shen:

Never tryed, is this going to work?

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


Hi,

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

Is there another solution for that case?

Thanks

Stephanie

HaoK:

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

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

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


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

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

Hope that helps,
-Hao


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

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


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

Hope that helps,
-Hao

Array property on a complex return type not deserializing to Array

HI,

I have a WS that returns a complex type let's call itJSONResultWrapper-one of the properties ofJSONResultWrappersay,Result, is an Array of another complex type say,JSONResult.

When this serializes down the wire, it looks like it has serialized correctly, but when it is deserialized back into an object at the client, instead ofResult being an Array orJSONResult,it is an object.

Sure, I can iterate through this and add each element into my array - but should I have to ?

c# code

public class JSONResultWrapper
{
...other props here...
public JSONResult[] Results;
...
}

--8<-----8<-------

[WebMethod]
public JSONResultWrapper GetResults(string SearchKey, string type)
{
JSONResultWrapper Jrw = new JSONResultWrapper();
.....
return Jrw;
}


--8<-----8<-------

JSON (from firebug)

{"AccommodationType":["Hotel","Apartment"],"Allocation":["Named"],"Results":[{"id":"694999631","ds":28,"dp":74,"tn" :4034,"b":3,"c":280460,"s":0,"u":0,"dd":0,"at":0,"al":0,"du":6,"ap":2,"cp":0,"r":"3*","p":"74","ip":1
,"an":"Tophotels Casino Royal","q":"s17056","dl":null,"e":1,"mo":0},{"id":"692909484","ds":28,"dp":74
,"tn":388,"b":2,"c":1701,"s":0,"u":1,"dd":1,"at":1,"al":0,"du":7,"ap":2,"cp":0,"r":"","p":"88","ip":1
,"an":"","q":"6HR1357","dl":"","e":1,"mo":0}]
}

Javascript.

--8<-----8<-------

TT.ResultCollection = function(InitValues) {

TT.ResultCollection.initializeBase(this);
......
this.Results = new Array();
.....
}


--8<-----8<-------

_onMethodComplete : function(result, userContext, methodName) {

try{
this.Results = $create(TT.ResultCollection,result);
}

--8<-----8<-------

I end up with this.Results.Results being an Object with properties, rather than an Array.

So far I have tried all sorts of types for Results ion the server but I realised that they were all serializing OK - it is the deserializing that is causing me problems.

What gives?

Cheers, all.

Have a look at http://www.microsoft.com/belux/msdn/nl/community/columns/jdruyts/wsproxy.mspx

You may need to use Jelle Druyts WSDL import modifier to fix the issue/


alternatively, have a look at the ajax-extensions converter class: http://ajax.asp.net/docs/mref/T_System_Web_Script_Serialization_JavaScriptConverter.aspx