views:

105

answers:

1

Can someone explain to me how you would use jeditable with an ASP.NET web form (and C# codebehind). I've got a bit of experience with web forms but not very complicated stuff, and haven't used much jquery before, and this is just puzzling me. I understand how to put it in and attach it to the element you want to be editable, it's what jeditable does when you submit the text field that I don't get. How do you handle that in the webform in order to save the changed text? Hope someone understands my issue... Cheers!

A: 

There are lots of ways to handle the POST that jEditable sends. I went with a very simple one. I made a new .aspx file and pointed jEditable to that. In there, you can access the form's POSTed fields with this.Request.Form["..."] to do whatever you intend to do. Here's a snippet:

protected override void OnLoad(EventArgs e)
{
    this.Response.Clear();
    this.Response.Cache.SetNoStore();
    this.Response.Cache.SetExpires(DateTime.Now);
    this.Response.StatusCode = 200;

    try
    {
        var postId = this.Request.Form["id"];
        var value = this.Request.Form["value"];

        this.Response.Write(value);

        switch (postId)
        {
            case "id1":
                // write 'value' to DB or whatever
                break;
            case "id2":
                // write 'value' to DB or whatever
                break;
            default:
                this.Response.StatusCode = 501; // Not Implemented
        }

        this.Response.End();
    }
}
Scott Stafford