Structured, well-formed and server-side composition of Json object for return parameter with RadWindow

1 posts, 0 answers
  1. Emanuele Savarese
    Emanuele Savarese avatar
    14 posts
    Member since:
    Apr 2007

    Posted 01 May 2007 Link to this post


    r.a.d.controls version

    Q4 2006 SP2

    .NET version


    Visual Studio version


    programming language


    browser support

    all browsers supported by r.a.d.controls

    I'm working first time on RadControls for ASP.NET to build my first test application. Sometime I need to send and receive in Javascript function object instead of values, but I can't found a way to create JSON object automatically.
    With JsonSerializer class e JsonAttribute class you can define C# classes and pass them to client javascript functions on fly with injection. With Serialize method and string type support you can manage simple object in server to client and client to client communications. But adding Deserialize functionality and support for IList property you can manage complex objects from client to client, client to server, server to client.

    Download sample and view step by step implementation.
    Step 1
    Define object to manage as C# class.

    Step 2
    Add custom attribute JsonAttribute defining property name in JSON object for each property.
    private string _userAction;   
    public string UserAction   
        get { return _userAction; }   
        set { _userAction = value; }   

    Step 3
    Insert this code in your C# class:
    public override string ToString()  
    return this.ToString('\'');  
    public string ToString(char stringDelimiter)  
    JsonSerializer s = new JsonSerializer(this.GetType(), stringDelimiter);  
    return s.Serialize(this);  

    Step 4
    Before injecting script in Dialog create C# class and then compose script.
    Example (server-side):

    RefreshArgs args = new RefreshArgs();   
    args.Source = "MyDialog";   
    args.SourceType = "RadWindows";   
    args.UserAction = "Process1";   
    InjectScript.Text = "<script type='text/javascript'>CloseAndRebind(" + args + ");</script>"

    Step 5
    Retrieve values from function from caller.

    function RefreshControls(refreshArgs)  
        alert(refreshArgs.Source + " (" + refreshArgs.SourceType + ") => " + refreshArgs.UserAction + " requested.");  

    I hope this code is usefull.

    Oppidum s.r.l.

Back to Top