Javascript - How To Use MS Ajax PageMethods To Call A Function On The Server

Jan 16, 2011

I have a project that uses PageMethods to call functions on the server. The server functions (written in C#) return the values as array of strings, without doing any kind of serialization and in the client side (from Js) the accessing of the return values is by using static variable called arguments. I found that sometimes for some users (cases are not repro) sometimes an exception occured

"WebServiceFailedException the server method 'Foo' returned invalid data. the 'd' property is missing from JSON."

Some searching on google I found that people are serializing the return values using DataContractJsonSerializer class and in js accessing the return value using one of the callback function Example:

function OnRequestComplete(result,
userContext, methodName) {
var Person = eval('(' + result + ')');
alert(Person.Forename);
alert(Person.Surname); }

So is the first technique is correct? or what?

P.S:

the function on the server is defined on the default.aspx.cs file as follows:

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] Foo(string s);

from the client side the calling is as follows

PageMethods.Foo("value",OnSuccess);

Also all the users have the same browser version (IE8)

View 3 Replies


Similar Messages:

AJAX :: Calling A Server Side Function From Javascript Without Using PageMethods?

Sep 17, 2010

i have used PageMethods to access the server side functions in javascript , but now my problem is that with pagemethods your controls will not go throught the full page lifecyle and these leads me to have "Object not set for an instance of an object" error. Now can someone come with a differnt approach without using pagemethods. What i want is to call a server side function , i dont want to pass any parameters to it

View 6 Replies

VS 2008 - Calling A Server Side Function From Javascript Without Using PageMethods?

Sep 17, 2010

i have used PageMethods to access the server side functions in javascript , but now my problem is that with pagemethods your controls will not go throught the full page lifecyle and these leads me to have "Object not set for an instance of an object" error. Now can someone come with a differnt approach without using pagemethods. What i want is to call a server side function , i dont want to pass any parameters to it

View 5 Replies

Javascript - OnBeforeUnload - How To Call A Server-side Function Without Ajax

Jul 22, 2010

What I want to do: dispose of a session upon detecting an "OnBeforeUnload" event in the client. I know it doesn't fire 100% of times (90% accuracy works fine for me)

Here I saw how to do it with ajax, this system, however, breaks down with ajax: I can't use it at all.

View 3 Replies

Call Javascript Function And Server Side Function From Linkbutton

Jan 27, 2010

<asp:LinkButton CssClass="button" ID="btnApply" runat="server" OnClick="btnApply_Click()" OnClientClick="Apply1('btnApply')" >
hi ihave this functin in .vb file
Protected Sub btnApply_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApply.Click
end sub

and javascript function also in aspx

function ApplySummerization(id)
{
alert("hai");
}

View 4 Replies

C# - JavaScript PageMethods Call Loosing HttpContext.Current State?

Dec 29, 2010

I am using JavaScript's PageMethod functionality where I am invoking a PageMethod which works like a gem. However I am having an issue in accessing the HttpContext's state which returns me a value "SYSTEM" for

HttpContext.Current.User.Identity.Name

which is not the actual current User Name.

I know there are couple options like storing HttpContext.Current in a Session or saving Context's state in some other custom container but given a web farm environment I am assuming that this will not work as expected.

Here is the code I am working on with

function MyFunction(){
PageMethod.MyPageMethod();
}

here is the signature of the server method

[System.Web.Services.WebMethod()]
public static void MyPageMethod()
{
// gives me "SYSTEM"
var user = HttpContext.Current.User.Identity.Name;
}

Also if I use the above code to access user name in OnLoad event of the page then it works fine and returns me the CurrentUserName.

I am trying to get the above code to work in an ASP.NET Webform... :)

So I am wondering if there is a way to access the current actual user in page methods without making use of sessions.

View 1 Replies

Web Forms :: Call A JavaScript Function From Server

Jan 7, 2011

I have a web form that has a button. The click event of the button submits the form for processing on the server. On the server, after the processing is complete, I want to call a JavaScript function. I don't want to attach it to a control. Just call it.

View 7 Replies

How To Call Javascript Function From Server Side

Jul 3, 2010

How to call JavaScript function from server side

View 2 Replies

JQuery :: Ajax Call In Javascript Function

Nov 4, 2010

i have a jquery .click() function that executes an .ajax() method call

[Code]....

when the .ajax() method executes succesfully it calls a javascript function

[Code]....

as you can see i have an .ajax() method inside my javascript function, is this possible? I am creating loop that starts on the finish listener of the soundmanager object. So when I need to make the ajax call to get he next url I need.

View 4 Replies

MVC :: Call Ajax.ActionLink From JavaScript Function?

Jan 6, 2011

I know that I do not want to actually use an Ajax.ActionLink from within a JavaScript function, but for the life of me I cannot figure out how to replicate the behavior. Here is what I have in my MVC 3 RC2 _Layout.cshtml:

[Code]....

I do NOT want to use:

[Code]....

Unless that can be made to populate at runtime, on demand from a script. manually clicking the ""Load Menu" ActionLink works exactly like I want except it requires the user to click the link; I want to do that for them... in this case from the Body onload event.

View 8 Replies

AJAX :: Call JavaScript Function From ValidatorCalloutExtender

Mar 1, 2011

I have ASP.NET form where i have Implemented Ajax ValidatorCalloutExtender for Validation Purpose. So can i call a JavaScript Function from Ajax ValidatorCalloutExtender for checking Correct Data entered by the User.

View 1 Replies

AJAX :: Codebehind - Call The Javascript-function ?

Jan 21, 2010

I'm having some trouble with making use of some AJAX-properties that are normally accessable after I've initialized a scriptmanager.

ie. This work:

[Code]....

Now, I would like to call the javascript-function 'testFunc()' from my ASP.NET Codebehind-file, and here's my problem. I keep getting "Sys is unidentified".codebehind-stuff: ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "testkey", "testFunc();", true);


Does anyone have good idea how to solve this?
Much appreciated. Thanks.

View 2 Replies

Web Forms :: How To Call A Server Side Function Using Javascript

May 19, 2010

I have a function in Code Behind, Can any one let me know "How would I call this function using javascript"?

View 4 Replies

Web Forms :: Call JavaScript Function From Server Side

Jul 26, 2012

I have javascript function like below

function SetScrollEvent() {
            window.scrollTo(0, document.body.scrollHeight);
        }

I have button within update panel. 

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
  <asp:button onclick="" runat="server">
    </ContentTemplate>
    </asp:UpdatePanel>

On button click i want to call javascript.

View 1 Replies

Javascript - Ajax Call Pass Parameters To Function?

Feb 7, 2011

What is wrong with this code? I am trying to pass parameters to a WCF function. I couldn't get this to work. I am getting Ajax error.

$.ajax({
url: applicationPath + "/Test.svc/GetData",
type: "POST",
dataType: "json",
data: '{GId":' + sender.get_value() + '"GName":' + sender.get_text() + '"mId":' + testId + '}',
contentType: "application/json; charset=utf-8",
success: function(result)
{
//trying to fill combobox here
},
});

View 1 Replies

AJAX :: Can Not Call Two Different Pagemethods With Two Service Methods

Oct 1, 2010

I am using an AJAX dropdownlist control with two dropdownlist. Instead of using a webservice to populate the data, I used the pagemethod to populate. My problem is the second droplist won't populate. I get a server error, 500 in the droplist. The first droplist populates fine.

BUT here's the real kicker. If I reverse the order of the public static function such that GetHelloList2 comes BEFORE GetHelloList1 in the code, then the GetHelloList2 works ...... it just seems like it is only firing one pagemethod event and allowign only one.

[URL]

View 5 Replies

Javascript - Call A Server Side Function On Leave Event Of A TextBox?

Jan 10, 2010

I am building a user registration form in asp.net. I want to check if the username is available or not on the leave event of the TextBox. I am not able to get the Leave Event of the TextBox.

Should I use OnBlur event of the Html TextBox.

View 1 Replies

AJAX :: How To Check Asynchronous Call Using PageMethods In Global.asax Using VB.NET

May 27, 2010

I am using PageMethods in my pages, and we have some requirement in which some maintenance process happened in certain time span, so in that time we set on DB flag consider as True False, I have written my code in Global.asax where in application_AcquireRequestState(...,...) Method I am checking the flag and depanding upon the flag I am redirecting my Page to one Maintenance dummy page, so application_AcquireRequestState() method working properly when page get postback or I am using thru any server control, but when I am using Asynchronous call using PageMethods in application_AcquireRequestState I am getting exception, Can anyone solve my problem I am using VB.NET.

[Code]....

View 1 Replies

Web Forms :: Call JavaScript Function In Server Side Button Click Event

Feb 7, 2012

I want to call JavaScript function in Server side Button click event of ASP.Net Button ....

View 1 Replies

AJAX :: Call JavaScript Function After UpdatePanel Refresh (Partial PostBack) Is Completed

May 7, 2015

[URL] .... am using this functionality in my project and it is working very fine but i am facing very strange issue while using this.

The above functionality is not working when we place dropdownlist and textbox inside updatePanel and ModalPopupExtender

The .aspx page where i am using ModalpopupExtender and UpdatePanel for DropDownList and Textbox is below

<%-- *************************** MODAL POPUP EXTENDER ***************************************************** --%>
<asp:HiddenField ID="HiddenField3" runat="server" />
<asp:HiddenField ID="HiddenField4" runat="server" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Div6" TargetControlID="HiddenField3"
BackgroundCssClass="modalBackground" CancelControlID="bclosemodalpopup" >
</cc1:ModalPopupExtender>

[Code] ....

The above code is not working with UpdatePanel but it is working if we remove DropdownList and Textbox from updatepanel.

The javascript code which i am using is below

<script type = "text/javascript">
var ddlText, ddlValue, ddl, lblMesg;
function CacheItems() {
ddlText = new Array();

[Code] .....

View 1 Replies

AJAX :: Is It Possible To Call A Custom Method Or Class Before Accessing Webmethod From PageMethods

Jan 19, 2010

is it possible to call a custom method or class before accessing webmethod from pageMethods ?

View 2 Replies

Web Forms :: Error While Accessing Page Label Control In WebMethod During AJAX PageMethods Call

Jul 16, 2012

I found this Article from link : [URL] .... that explains how to call server-side Method from javascript,

I used your code, my server-side function is static, public, and also I added

[System.Web.Services.WebMethod] 
and
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">

View 1 Replies

Web Forms :: Call Javascript In Codebehind (one Function But Twice Call)

Dec 13, 2010

i have a question about call javascript in codebehind. my page has two parts.one part for enter information about manager and another part for usualuser.each person has mellicode.that it has speicail code.i wrote it with javascript and call it with this code:

[Code]....

when i click in btnpazireshsabt i should check mellicode for manager.i call it :

[Code]....

i want to disable btnsabt when i click in

[Code]....

View 5 Replies

JavaScript - How To Implement Super Fast AJAX Callbacks/PageMethods

Feb 7, 2011

I am designing an ASP.NET web application (.NET 4.0) which basically has a page that should interact with the code behind every 1-2 seconds (Using Client callbacks or PageMethods via ScriptManager or jQuery.ajax) It'll be hosted on an intranet, so a 1-2 second refresh rate is kind of reasonable.

How can I make the page to access the web service/pagemthod in the code behind in a timeply manner (e.g. every 1 second). Should I use a javascript timer (I'm not familiar with javascrip very much)?

Although the site is hosted on an intranet, but I still need to implement a good approach to reach the desired refresh rate. the amount of data being transfered is about 1KB in each interaction. What are your recommendations on my design regarding this? (using callbacks or ScriptManager or jQuery.ajax,...

View 3 Replies

Call Javascript Function From Code Behind After Server Side Code Executes

May 25, 2010

I have an asp.net button, that when clicked calls a code behind function. The function does some evaluation, and then I want to call javascript from within this asp.net function.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved