.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

Ajax.net 3.5 JSON and WCF Serialization

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :ASP.Net
 
 I'm trying some WCF ajax.net 3.5 out for the first time, and I'm having some difficulties.  I have a WCF Service which I have connected to in my aspx page using <asp:ScriptManager>.  I have a custom object which has been decorated as a [DataContract].  I'm calling the object from javascript successfully, I can see the JSON response in FireBug, but Sys.Serialization.JavaScriptSerializer.deserialize() chokes on it.  I'm sure I'm making a noob mistake, but I used up all my patience getting the Web.Config values right for running the WCF service :)Here's a mockup of what I'm doing.// The custom objectnamespace my.namespacehere{ [DataContract] public class UserAccountData : IComparible { [DataMember] public Guid AccountGuid { get; set; } [DataMember] public string Email { get; set; } [DataMember] public string UserName { get; set; } // Ctor and IComparible stuff omitted }}// The WCF Service .svc.cs codenamespace my.namespacehere{ [ServiceContract( Namespace = "AdminServices" )] [AspNetCompatibilityRequirements( RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class LookupServices { [OperationContract] public UserAccountData GetUserAccountData( Guid accountGuid ) { // The code for the stat


View Complete Post


More Related Resource Links

Templating for Json in an AJAX call

  

Hi,

I am new and working on JQuery. I been looking around for templating in ASP.NET.

Suppose I have Json data coming from web service in an AJAX call. Is there any way to use that in Template and than fill that template at the required place?

Any good approach.


Thanks



which approach is better? client side callbacks or ajax using json for programming?

  

Hello! Friends,

                   I just wanted to know whether clientside callbacks or ajax is better for programming? I want to develop a webbased ERP. 


Thanks...


JSON AJAX WCF SERVER METHOD FAILED 404

  

Hi guys

Am having a hard time trying to make my wcf work in asp.net ajax.

I have my service hosted on another machine: https://mydomain.com.au/myservice/json

I am calling the service from my http://localhost/default.aspx

When i call it it keeps returning me the error saying server method "MyMethod" failed and status code is 404

 

Here's my service setup.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
	<script language="javascript" type="text/javascript">

		function Suceeded(msg) {
			alert("completed");
			// Do something with the response data here.
			//  Expect it to consistently have no .d.
		}

		function Failed(msg) {
			alert("failed");
			// Do something with the response data here.
			//  Expect it to consistently have no .d.
		}

		function CallWCFTwo() {
			var proxy = new tempuri.org.IAustPostService();
			var hellp = proxy.Ping(Suceeded, Failed, null);
		}

		function CallWCFThree() {
			var proxy = new tempuri.org.IMyService();
			var hellp = proxy.MyMethod("value 1", "value 2", Suceeded, Fa

jquery ajax - bind json to dropdownlist

  

Hi,
I'm using jquery ajax to populate a dropdown list to avoid page refresh via a webmethod.

My webmethod returns a json string. My question is how can i bind this to my asp.net dropdownlist?

See below for jquery code:

function getTeamid() {
        var teamid = $(".ccTeam").val();            
        $.ajax({
            type: "POST",
            url: "NewJob.aspx/sayHello",
            data: "{val:" + teamid + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                     AjaxSucceeded(msg);
                },
                error: AjaxFailed

        });
    }

    function AjaxSucceeded(result) {
              alert(result.d);
          }
                    
    function AjaxFailed(result) {
          alert(result.status + ' ' + result.statusText);
      }  

See below for webmethod code:

[WebMethod()]
        public static string sayHello(string val)
        {
            DataTable dt = dbTeam.getJobTypesByTeamid(val);
            
            return Intranet.Core.Util.GetJSONString(dt);            
        }  



 


jquery ajax json

  

Hi,

I've finally got my dropdowns populating via jquery,ajax and json (via page methods). It works fine, until I submit the page I get error shown below. What's the best way of fixing this?

Part of me is tempted to just install asp.net ajax/update panels and use this, however, I really want to avoid this as I want to stick with jquery ajax and json especially as I've spent time learning this. thanks.

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation. 


 


ASP.Net MVC JSON Serialization and the DataMemberAttribute

  

According to the documentation I've read, the only thing needed to serialize JSON in MVC is a call to Json().  However, I've found that doing this ignores the [DataMember(Name="")] attributes in my models. 

Here's an example:

Model:

[DataContract]
public class Person
{
	[DataMember(Name = "first")]
	public string FirstName { get; set; }
	[DataMember(Name = "last")]
	public string LastName { get; set; }
}

Controller:

public JsonResult JsonTest()
{
    Person p = new Person()
    {
	FirstName = "Darth",
	LastName = "Vader"
    };

    return Json(p);
}

Output:

{"FirstName":"Darth","LastName":"Vader"}

The JSON attributes SHOULD be "first" and "last."  However, they've retained their string representation of the original class.  Can anyone help me understand what I'm doing wrong?

Thanks,

Rob

 


Microsoft AJAX CDN

  
Content delivery networks (CDNs) are composed of "edge cache" servers that are strategically placed around the world at key Internet network points. These "edge cache" servers can be used to cache and deliver all types of content - including images, videos, CSS and JavaScript files.

Using a CDN can significantly improve a website's end-user performance, since it enables browsers to more quickly retrieve and download content. For example, instead of having a browser request for an image traverse all the way across the Internet to your web server to download, a CDN can instead serve the request directly from a nearby "edge cache" server that might only be a single network hop away from your customer (making it return much faster - which makes your pages load quicker).

AJAX GridView Checkbox Select All in ASP.Net

  
In the previous article GridView Select Multiple Rows you learnt the multiple row selection in GridView control. Here you will get the C# code sample to select all the gridview rows using single checkbox server control. You can highlight the selected rows with different color and Font state Bold. If you want to use the selection values on different ASP.Net

AJAX GridView Paging and Sorting using C# in ASP.Net

  
To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

GridView Paging Using Ajax in ASP.Net

  
To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

jQuery $(document).ready() and ASP.NET Ajax asynchronous postback

  
Many call it the ASP.NET jQuery postback problem, but using the technique below should make it no problem anymore. $(document).ready() isn't called after an asynchronous postback. What this means? You lose the functionality that should be executed within $(document).ready() after an UpdatePanel rendered its contents after an asynchronous postback.

Making Ajax Callbacks to the Server Using jQuery with ASP.NET

  
In the first part of this article series I introduced jQuery's functionality and how it provides a rich client side programming model. This time around I'll expand on these concepts and show you how you can use jQuery in combination with ASP.NET using it as an AJAX backend to retrieve data. I'll also discuss how you can create ASP.NET controls and otherwise interact with jQuery content from ASP.NET pages in WebForms.


jQuery is just a JavaScript library so it will work seamlessly with ASP.NET both from page code as well as through backend driven code using the Page.ClientScript object or ScriptManager. You can use jQuery on its own as a client side and Ajax library that communicates with ASP.NET or you can use jQuery in combination with ASP.NET AJAX. The two actually complement each other quite well as jQuery provides functionality that the ASP.NET AJAX library does not and vice versa. For the most part the interaction between the two libraries is trouble free except for a few very rare edge cases.

Building a grouping Grid with GridView and ASP.NET AJAX toolkit CollapsiblePanel

  
I've posted an update to this post to apply on demand loading of Details data using ASP.NET AJAX PageMethods. I'm demonstrating the usage if CollapsiblePanelExtender client events on the new post. Check it out.

I admit, Matt Berseth is really inspiring me! Few days ago I pass through 2 of his great posts:

.Surrounding your Data Table and Dialog Controls with ComponentArt Styled Panels
.Building a Grouping Grid with the ASP.NET 3.5 LinqDataSource and ListView Controls
The first one is pure design tips one which I used for making good presentation of my demo here. The 2nd post is actually the idea.

Using jQuery to directly call ASP.NET AJAX page methods

  
Here I am looking to explain how to call page methods using jQuery. Using jQuery to directly call ASP.NET AJAX page methods

Use jQuery and ASP.NET AJAX to build a client side Repeater

  
By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

jQuery live() and ASP.NET Ajax asynchronous postback

  
The issue is that normally $(document).ready() is called when the DOM is ready to be manipulated. But this doens't happen after an ASP.NET Ajax asynch postback occurs.

This means that the initial jQuery bindings won't be automatically available after the asynchronous postback is over. I underline "automatically" here because my last post describes more possibilities, how this issue can be worked around.

Use jQuery and ASP.NET AJAX to build a client side Repeater

  
By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

To that end, I'm going to walk you through these four steps to effectively implementing a client side Repeater, using ASP.NET AJAX and jQuery:
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend