s-a-n
s-a-n

Reputation: 787

Label Textbox ServerControl

Can I create a server control, where it loads as a label and on user click becomes a text box with two buttons(save,cancel) on the bottom right corner and then on pressing save becomes a label again with the entered text or cancel will cancel the edit(if any) and becomes a label again with the existing text?

Upvotes: 0

Views: 40

Answers (2)

Devendra Soni
Devendra Soni

Reputation: 1934

I have created a JSfiddle for the same:-

http://jsfiddle.net/c2S5d/29/

Code:-

$(function() {
    $("#lbl").click(function() {

        var text = $("#lbl").text();
        $("#lbl").hide();
        $("#edit").show();
        $("#text").val(text);
    });
    $("#save").click(function() {
        //make call to server if you want to save the value in DB
        var text = $("#text").val();
        $("#lbl").text(text);
        $("#edit").hide();
        $("#lbl").show();

    });
    $("#cancel").click(function() {

        $("#edit").hide();
        $("#lbl").show();

    });
});

in Save button event you can make ajax call or whatever you want to do...

Upvotes: 1

prog1011
prog1011

Reputation: 3495

Upvotes: 0

Related Questions