Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Wednesday, March 28, 2012

PageMethods CallBack Wont Fire

What conditions will cause the callback function to not fire when using the PageMethods class?

First my javascript:

<scripttype="text/javascript"language="JavaScript">

function FindTheResult()

{

var txt = document.getElementById("ctl00_contentPlaceHolder_txtBib").value;

PageMethods.FindResultMethod(txt, FindResultDone);

window.status = txt;

returnfalse;

}

function FindResultDone(arg)

{

window.alert(arg);

}

</script>

and then my codebehind:

[WebMethod]

public string FindResultMethod(string bib)

{

return "Hello";

}

FindResults() is firing because my status bar gets updated. But the FindResultDone function is not firing.

A client script error in javascript may have happened in this line:

PageMethods.FindResultMethod(txt, FindResultDone);

In this line, FindResultDone() is expecting a parameter but was not supplied


Ok, that makes FindResultDone actually fire. But how do utilize the return string from my WebMethod:public string FindResultMethod(string bib) ?

Leaving out the ( ) and any paramaters usually just passes the return string back to the callback method. See this atlas.asp.nettutorial code. The callback has no parameters, yet the function does.

This all worked flawlessly with the October release.

AlvinVi wrote:

A client script error in javascript may have happened in this line:

PageMethods.FindResultMethod(txt, FindResultDone);

In this line, FindResultDone() is expecting a parameter but was not supplied


Hi,

mxmissile wrote:


PageMethods.FindResultMethod(txt, FindResultDone);

This statement is correct, you don't need to add the () or any parameters because you have to pass a reference to the method (callback) that will be called when the server method returns.

I've tried your code (that seemed correct to me) on a machine and in fact everything went ok: the callback is fired and the string is displayed.

But then I've tried it on another machine and I got the strange behavior that you reported: the callback isn't fired because the asynchronous request returns a response with status code 500 (Internal Server Error). You could try to make the following call:

PageMethods.FindResultMethod(txt, FindResultDone, FindResultTimeout, FindResultError);

and then add these two functions:

function FindResultTimeout() {
alert('timeout');
}
function FindResultError(result, response) {
alert(response.get_statusCode());
}

Try to run the code and see what happens: probably the FindResultError callback will be fired.

Now, I suppose that you have added an <atlas:ScriptManager> tag in your page. Try to add a reference to a web service (for example, create a simple WebService.asmx)

<atlas:ScriptManager id="scriptManager" runat="server">
<Services>
<atlas:ServiceReference Path="WebService.asmx" />
</Services>
</atlas:ScriptManager>

and the run the code: which callback is fired now? In my case, the FindResultDone callback is fired and the response error disappeared...

I think it's a strange behavior.. I'll try to understand what is happening, but has anyone got ideas on what is going on?

Ok, ill try adding the webmethod to a seperate asmx file to see what happens.

I also have some other data:

function FindResultError(result, response) {
alert(response.get_statusCode());
}

When I do this, the alert window just says "null", so the error function is being called at least I think.

My page is using a Master Page, when I move the code to a "un-master page"ed" aspx file it works great.

I started a new test atlas project and everything is working great, until I start using Master Pages. It fails if I put the <atlas:ScriptManager tag is in the <head> of the Master Page or in the content section.

Anyway thanx for the input, still hacking at it...


Hi,

mxmissile wrote:


My page is using a Master Page, when I move the code to a "un-master page"ed" aspx file it works great.


You mean the first code you posted? I've tried it without a master page and it's working on a machine, but failing on another.

mxmissile wrote:


Ok, ill try adding the webmethod to a seperate asmx file to see what happens.


Just create a new web service (WebService.asmx), reference it in the<atlas:ScriptManager> tag but continue to call the method definedin your page (PageMethods.FindResultMethod). In my case this solved theproblem but it's a strange behavior.

Monday, March 26, 2012

PageRequest context

I know the WebRequest class in js has a userContext property but how do I do the same in a PageRequest class.

Maybe I am asking the wrong question.

I want to keep track of which control raised the event (postBackElement property) so that when the request completes, I can set some properties for the control that raised the event.

Thanks.

Try to take a look at this link?about?WebRequest from MSDN -?http://msdn2.microsoft.com/en-us/library/system.net.webrequest.aspx
Is?PageRequest Class?you?said?in?your?last?post?in?Java? If?yes,try?to?take?a?look?at?this?link?about?PageRequest?Class
http://docs.jboss.org/jbportal/v2.2/javadoc/org/jboss/portal/theme/page/PageRequest.html?
http://www.valtira.com/api/cms/com/valtira/cms/client/PageRequest.html
Wish the above can give you some helps.

PageRequestManagerParserErrorException when using a class with asynchronous calls

Hi all,

in the last days i come to a curious problem. On a page i use a GridView to show some data, and on select i show the details in a DetailsView. The Page inherits from a MasterPage and the controls inside an UpdatePanel. The GridView and the DetailsView are populated from different methodes of the same WebService. The WebService is in the same project and a class in App_WebReferences is generated also for testing the WebService function. There are no JavaScriptCalls to the WebService, all is pour C# in codebehind. Now to the problem. When initialice a proxy to the class in the webreference, all works fine and as axpected. But when i generate a class from the wsdl-file with wsdl.exe and use this proxyclass with asynchronous methods inside, the following error pops up:

"Sys.WebForms.PageRequestManagerParserErrorException: The Message received from the Server coul not be parsed. Common couses ..."

The curious is, the first pageload in browser is error free and the firts select also. But when i select a second time a row in the GridView the error pops up, whatever row i select. There is absolute no Response.Write in the hole project and tracing is diabled also.

I use the same struct on several pages in this project and that works. On some pages in this project i use asynchronous calls to WebMethods to populate controls in UpdatePanels without any problems.

Thanks for reading

Problem NOT solved in RC1.


I figured out, the problem comes from my CacheProfile. The WebMethod cache compete with the CacheProfile from the web.config. Simply changed thevaryByParam Attribute and all works like expected.

Saturday, March 24, 2012

Paint Event

I'm new to asp.net ajax. and Im using vb.net class to develop the page. Can the drawing class be implemented here? Is the picture box in vb same as image in asp? I tried with event handler for image1.paint but it .paint gives error...

No, images in ASp are completely different. You can use GDI+ to draw, however, but it's a bit different from winforms development. Consider the tutorial athttp://www.samspublishing.com/articles/article.asp?p=25487&seqNum=3&rl=1 as a decent place to start.

paul