我正在尝试使用asp.net隐藏字段将javascript文本框的值传递给服务器。不知道在后面的代码中做什么来保存提交的值。
$(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" />
<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="" />
答案 0 :(得分:1)
在代码隐藏(C#)代码中(它应该是与您的页面名称匹配的.CS类)创建(如果尚不存在)处理click事件的函数&#34; btnCopy_Click&#34;在那里,您可以放置代码来更新文件夹创建。使用IO库来做...我会为你寻找一个例子
答案 1 :(得分:0)
所以这就是我最终如何使用它。 jQuery引用了隐藏字段,我在后面的代码中调用它来传递值。非常感谢用户AhmedGadir的所有帮助。
$(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;