2

I am trying to pass the value of a javascript textbox to the server using an asp.net hidden field. Not sure what to do in code behind to save submitted value.

$(function () {
$(":asp(btnCopy)").live("click", function (e) {
    e.preventDefault();
    $("<div></div>").dialog({
        resizable: false,
        modal: true,
        title: "Do you want to rename this folder?",
        height: 100,
        width: 300,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
                var name = window.prompt("Please enter new folder name", "");
                function getNewFolderName() {
                    var newFolderName = 'name';
                    document.getElementById('<%=newFolderName.ClientID%>').value = "";
                }
                __doPostBack($(":asp(btnCopy)").prop('name'));
            },
            "No": function () {
                $(this).dialog('close');
                alert("Folder saved without rename");
                __doPostBack($(":asp(btnCopy)").prop('name'));
            },
            "Cancel": function () {
                $(this).dialog('close');
            }
        }
    });
});

});

<asp:ImageButton ID="btnCopy"  runat="server" SkinID="Copy" ToolTip="Click to copy folder."
                        OnClick="btnCopy_Click" Enabled="false"  />&nbsp;
                    <asp:ImageButton ID="btnCancel" runat="server" OnClick="btnCancel_Click" ToolTip="Click to go to Library home."
                        SkinID="Cancel" />
                    <asp:HiddenField ID="newFolderName" runat="server" Value="" />
Leonardo Wildt
  • 2,529
  • 5
  • 27
  • 56

2 Answers2

1

In your code behind (C#) code (it should be the .CS class that matches your page name) create (if not already exist) a function handling the click event "btnCopy_Click" There you can put your code to update the folder creation. Use the IO library to do that... I will look for an example for you

Ahmed Gadir
  • 364
  • 1
  • 9
  • Look at this For IO (folder changing code) http://stackoverflow.com/questions/2023975/renaming-a-directory-in-c-sharp – Ahmed Gadir Feb 19 '15 at 19:33
  • Try this $(this).dialog('close'); var name = window.prompt("Please enter new folder name", ""); function getNewFolderName() { var newFolderName = 'name'; document.getElementById('<%=newFolderName.ClientID%>').value = newFolderName; } – Ahmed Gadir Feb 19 '15 at 19:59
0

So here is how i finally got this to work. jQuery referenced the hidden field and i called it in code behind to pass the value. Thanks Alot to User AhmedGadir for all his help.

    $(function () {
$(":asp(btnCopy)").live("click", function (e) {
    e.preventDefault();
    $("<div></div>").dialog({
        resizable: false,
        modal: true,
        title: "Do you want to rename this folder?",
        height: 100,
        width: 300,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
                var name = window.prompt("Please enter new folder name", "");
                $(":asp(newFolderName)").prop('value', name);
                __doPostBack($(":asp(btnCopy)").prop('name'));

            },
            "No": function () {
                $(this).dialog('close');
                alert("Folder saved without rename");
                __doPostBack($(":asp(btnCopy)").prop('name'));
            },
            "Cancel": function () {
                $(this).dialog('close');
            }
        }
    });
});

});

    string folderName = newFolderName.Value;
Leonardo Wildt
  • 2,529
  • 5
  • 27
  • 56