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

Wednesday, March 28, 2012

Very weird error. Ajax controls call default.aspx

I have a few pages in my site... and for some reason, if there's any ajax controls on the page, it calls default.aspx and runs the code every time any aspx page with an ajax control exists on it. Problem is, default.aspx resets my session variables.

Why does Ajax call the default.aspx page code? It only runs the CS file... it doesn't actually show the default.aspx page.

I doubt it calls it. Do you have a component in your site somewhere that's got a url of "/" attached to it somewhere, and that's invoking the default page?


it only seemed to only happen when I have Certain Ajax controls on the page. Note, it only does it with Internet Explorer 6 and 7. Firefox seems to be fine.

For example, I have a collapsible PAnel in each row of a Gridview. That is in an UpdatePanel. When the Gridview is populated (and I have a breakpoint on the default.aspx.cs file), it goes through that code. Well, I set my session variables on that page, so in essence it resets them.

It seems like it does this AFTER the page is loaded, because the labels that show content based on those session variables aren't updated until I go to a new page.

It only does this when I have a collapsible panel in IE. The panel is set to collapsed.


Actually, it appears that AJAX is clearing the Session Variables. I don't know where it's doing this, though.

Monday, March 26, 2012

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.

Wednesday, March 21, 2012

Web Service and Custom Type(Enumeration)

Hello,

I have a web service with a method called "Login" Login returns a custom enumeration type called "MethodStatus". I am trying to call this method in Atlas, my client code is below

 function OnbuttonGo_click() { //Call script proxy passing the input element data var object = Crisp.ParentWebService.MainService.Login( 'd','d', //params OnComplete, //Complete event OnTimeout //Timeout event ); return false; } function OnComplete(result) { alert(result); } function OnTimeout(result) { alert("Timed out"); }
This method works fine if I change the type in my Login status to String but when I use my enumeration it fails
giving me the following error message:
Key cannot be null.
Parameter name: key
Server Error in '/AtlasWebSite1' Application.
Key cannot be null.
Parameter name: key
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Key cannot be null.
Parameter name: key
Source Error:
An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentNullException: Key cannot be null.
Parameter name: key]
System.Collections.Hashtable.ContainsKey(Object key) +2773989
System.Collections.Hashtable.Contains(Object key) +4
Microsoft.Web.Services.ClientProxyGenerator.EnsureNamespace(Type t) +46
Microsoft.Web.Services.ClientProxyGenerator.GenerateEnumTypeProxies(IEnumerable`1 enumTypes) +117
Microsoft.Web.Services.ClientProxyGenerator.GetClientProxyScript(WebServiceData webServiceData) +339
Microsoft.Web.Services.WebServiceClientProxyGenerator.GetClientProxyScript(HttpContext context) +263
Microsoft.Web.Services.RestClientProxyHandler.ProcessRequest(HttpContext context) +79
Microsoft.Web.Services.HandlerWrapper.ProcessRequest(HttpContext context) +30
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +401
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +117
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
     <!--
[ArgumentNullException]: Key cannot be null.
Parameter name: key
at System.Collections.Hashtable.ContainsKey(Object key)
at System.Collections.Hashtable.Contains(Object key)
at Microsoft.Web.Services.ClientProxyGenerator.EnsureNamespace(Type t)
at Microsoft.Web.Services.ClientProxyGenerator.GenerateEnumTypeProxies(IEnumerable`1 enumTypes)
at Microsoft.Web.Services.ClientProxyGenerator.GetClientProxyScript(WebServiceData webServiceData)
at Microsoft.Web.Services.WebServiceClientProxyGenerator.GetClientProxyScript(HttpContext context)
at Microsoft.Web.Services.RestClientProxyHa

You're doing something else wrong somewhere, and I don't know from your code what it is. I just did the part that you think is tripping you up, and it works fine. Code follows:

<... Html stuff that builds a pair of text boxes and a button ...>

<script type="text/javascript">

function button_Click()

{

var name = document.getElementById("userName");

var pass = document.getElementById("passWord");

requestService = TestEnums.MyService.Login(

name.value, pass.value

OnComplete,

OnTimeOut);

return false;

}

function OnComplete(result)

{

alert(result);

}

function OnTimeOut(result)

{

alert('timed out');

}

</script>

<... closing html stuff ...>

now the web service

<... web service header, using statements, and so on ...>

[WebMethod]

public Status Login(string a, string b)

{

if(a==b)

return Status.Authenticated;

else

return Status.Anonymous;

}

<.... Enum ...>

publuic enum Status

{

Anonymous,

Authenticated

}

Now, what happens is that the thing runs, and it alerts 0 or 1. I suspect you'd have to handle the enum in javascript as well in order to translate the enumeration into something meaningful on the client. But the bottom line is that passing a custom type is not error-generating action.


Hello,

I have fixed the problem now the problem was because I never set a namespace for the enumeration. I had set a namespace for my service and not for my enumeration.

Thank's alot for your help!

Rob


No problem, glad you found it!

web service call by javascript

In my AJAX enabled website, call web service by javascript.

Web Service:

<WebService(Namespace:="http://tempuri.org/")> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<ScriptService()> _Public Class SimpleServiceInherits System.Web.Services.WebService<WebMethod()> _Public Function Addup(ByRef int1As Integer,ByRef int2As Integer)As Booleanint1 = int1 + int2Return TrueEnd FunctionEnd Class

Javascript:

var num1=1, num2=2;function Button1_onclick() {HangmanService.Addup(num1, num2, OnComplete);}function OnComplete(ret){if (ret == true){alert(num1);// should popup "3"}}

Actually, I got error of "System.InvalidOperationException -- Can't convert object of type "System.Int32" to type "System.Int32&" instead of "3". So do I have to get number from return value?

Hi,

the reference to num1 on server side has nothing to do with the reference to num1 on client side, they are two separate variables. Therefore Addup must return a number.


Try this,
 
<WebService(Namespace:="http://tempuri.org/")> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<ScriptService()> _Public Class SimpleServiceInherits System.Web.Services.WebService<WebMethod()> _Public Function Addup(ByRef int1As Integer,ByRef int2As Integer)As Stringint1 = int1 + int2Return int1.toString()End FunctionEnd Class

Javascript:

var num1=1, num2=2;function Button1_onclick() {HangmanService.Addup(num1, num2, OnComplete);}function OnComplete(result){alert(result); // should popup "3"}
WS

Thank you guys' reply.

The problem is not about return value but javascript even can't call the web method. Maybe in javascript a variable can't be reference parameter.


Ah, gotcha,

It's a little bit odd how you call your webservice function. Should it be ...

SimpleService.Addup(num1, num2, OnComplete); ......???
WS

I believe you should return the number in the return value if it's possible.
AJAX serializes input parameters and return values. I think that using ByRef is not going to work.
If you need to get those two values back (bool and int), you should consider returning a different type.

Hope this helps,

MaĆ­ra


Thanks for your reply. I just wanna know if it works. Anyway, I know it.

Web Service Call

Hi,
Is it possible, with atlas, to call a web service that is out-side my application domain
ex. http://sample.com/sample.asmx
ThanksThe issue with doing this is that you will run into the browser's cross domain scripting restrictions. But if the other domain is trusted, and XMLHTTP doesn't block the call, then I believe it should work. Note that for this to work, the web server that processes the request (i.e. that has sample.asmx) needs to also be running Atlas.

It's not possible to use the web server associated with the domain like a "proxy" to call other web service outside the trusted domain? It's just an idea and I think that an automated proxy generator for remote web service can be very usefull. In addiction in this way the remote web service doesn't need to run Atlas.

web service call failed: 500 using ajax hovermenu and web service

Hi there,

I'm using a hovermenuextender attached to a templatefield of a gridview, and everything seemed to work fine.. however I've moved on to add dynamic attributes to the hovermenu. Now I get the error "web service call failed: 500" in place of the output I want (on the hovermenu's panel).

When accessing the web service I created (directly through the browser) everything works fine..

here's my hovermenuextender dynamic attributes

DynamicContextKey='<%=eval("refnumber") %>'

DynamicServiceMethod="GetSearchDetails"

DynamicServicePath="Services.asmx"

DynamicControlID="lbdynamiccontent"

I've done a bit more fiddling.. so this extra info may be useful.. it may not (I've only just started playing with this).. using firebug, I can see the response to the post to the webservice fails with "Invalid web service call, missing value for parameter:".. I tried swapping my service for the helloworld one, and that works fine! Why is my parameter not being sent? I was thinking the parameter is the dynamiccontextkey - is that correct?

Any help would be greatly appreciated! I also saw error 12030 instead of 500 crop up, but that seems to have gone (!!!)

cheers, Chris

Hi,

I fail to reproduce the issue. Can you show me more of your codes?


i think you are using the DynamicPopulate instead of Hovermenu. In that case i think you should check its documentationhttp://ajax.asp.net/ajaxtoolkit/DynamicPopulate/DynamicPopulate.aspx. Basically i think you are having passing the contextKey in the WebService, can you pls check if the db field is not null or it contains some value.

Web Service Call executes 2 times !

Hello

When I make a call to an asynchronous web service the call is executes 2 times ! Except when I display an alert message before treating the result from the server, it only executes 1 time.

Here is my code on the client side:

functiononComplete(result)
{
var count=result.rows.length;
varcity=$get("<%= txtCity.ClientID %>");

if (count== 1)
city.value=result.rows[0].upName; (upName is the name of the city in the database)
else
{

alert('stop'); ---> WHEN I ADD THE ALERT MESSAGE HERE THE WEB SERVICE IS EXECUTED ONCE
----> WHEN I OMIT THE ALERT MESSAGE IT IS EXECUTES TWICE !

varsel=document.createElement('select');
sel.setAttribute('id', 'ddlCity');
sel.options[0]=newOption('<-- Select your city-->');

for (vari=0;i<result.rows.length;i++)
sel.options[i+1]=newOption(result.rows[i].upName);

document.getElementById('divCity').appendChild(sel);
}
}

Already found where my problem was.

When using my keyboard of my notebook, I have to use the SHIFT key to enter the numbers, and there are always 2 events triggered.

1) releasing the last digit itself to search
2) releasing the SHIFT key

So... problem solved :-)

Web service call from javascript and SQL Server 2005 Express

Hi,

I'm developing a web application that uses Ajax to call web services using javascript.

The web service must connect to a SQL Server 2005 Database (express edition) and uses a dynamically created connection. The connection string used to create the connection is right because it works for web page data loading and it uses SQL server authentication mode.

In the development environment the application works correctly, but when deployed on a different machine with a different SQL Server installation, the sql connection in the web service fails returning the following error:

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.

I've tried all suggested changes in SQL Server Configuration Manager andSQL Server Surface Area Configuration, enabling both tcp/ip and named pipes for remote connection, but the connection is still not working.

The server has a windows XP professional SP2 operating system and windows firewall is active, but i have enabled http from lan and sql server access.

Can you suggest me something?

I must add or change something in the web.config file?

I feel?that this problem is in the permissions connecting Web?Service?to?SQL?Server?2005.I give you some suggestions for your reference as the following:
Try to add Network Service in the virtual directory permissions of IIS and make sure the execute permissions is Scripts and Executables through?right mouse clicking the virtual directory?and?choosing?properties?in?IIS.

Web service call to different sub domain

I have a web site at http://sub1.mysite.com and a web service at http://sub2.mysite.com. I'm trying to use a script reference in my script manager to allow AJAX calls to the web service. When I trigger the call, I get a popup that says the call failed. The error appears to be because a 404 is coming back on the web service call. I know the script reference has to be within the same domain, but does it have to be in the same subdomain? Is there a way to trick it to work (like setting document.domain to allow javascript)?

It is not possible to call any other WS which resides in different Domain. You can read this article(Cross Doman Sectiion) for more detailshttp://dotnetslackers.com/columns/ajax/MashitUpwithASPNETAJAX.aspx.
Maybe you can try this JSONP approach to solve your issuehttp://weblogs.asp.net/rashid/archive/2007/09/28/implement-jsonp-in-your-asp-net-application.aspx

Web Service calls .NET 2.0

I have an ASP.NET application in .NET 1.1 that makes a web service call using the Begin{WebMethod} call and then returns to the page and redirects to another page. The Async callback is returned later when this is done and I log any errors that this web method call may have had to the event log. The web page does not wait for the response because it's role is to fire it off and then go on. I am trying to move to .NET 2.0 and have an issue where the Async call for 2.0 will not allow me to redirect until the web service has completed. I do not need a response from my web service and would like to move on to another web page. I basically have switched to making this a synchronous call as how 2.0 is handling it is synchronous.

Thanks for any and all help.

Hello Mladinichs,

check out the Ajax video that shows how to use client side Async call back.

http://www.asp.net/learn/ajax-videos/video-79.aspx

I hope it helps.


Client side is not really what I'm looking for. The button click is gathering up info from the screen, performing a save operation and then kicking off an async process. Any thoughts?


Hi,

If your wanting to do this on the client side, does this work?

function DoSave(){

YourSavingService.SaveData()

document.location.href = "yourNextURL.aspx"

}

Cheers Si


This application is an existing application in production and I'd rather not re-write this entire functionality to be client-side. Is there no way to do this server-side?


Hi,

I suggest using a separate thread to run the task which is currently running on the main thread of the web service that halts it form return soon.

For instance, say your web service is like this now:

void fun() { doSomething(); }

change it to:

void fun() {Thread thrd = new Thread(new thredInfo(doSomeThing); thrd.Start(); }

Web service class undefined on Client load

Having tested a simple atlas web method call from the client which is fired by calling a javascript function on a button client side click event -it works perfectly.

The problem is I need this function called when the page loads, however whenever calling this function from either the body onload client side event or by using the RegisterStratupScript on the server side page load method, I get a javascript error refering to the web service class name as being undefined.

In theory this should work, Am I missing something regarding my understanding of the atlas lifecycle perhaps?

Please help!
Thanks

Dynamic script references (included in the References section of the ScriptManager) are not available until after page loading. To use these, you need to hook the Load event of the Application object. Declaratively, you can do this with:

<application>

<load>

<invokeMethod method="MyMethodName" />

</load>

</application>

Alternatively, you can statically include the service with a <script> tag.


A simpler syntax to do this is to have:

<application load="OnApplicationLoad" />

This goes into your <components>. So you would have something like this:

<script type="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<references>
</references>
<components>
<application load="OnApplicationLoad" />
</components>
</page>
</script>

David


BTW, I should mention that there is yet an easier way: just name your method pageLoad and it will be automatically called without having to be registered. See theAtlas docs for some examples.

David