1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
Client-Side
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div class="container">
<div id="Groups">
<asp:TextBox ID="txtNewGroup" runat="server"></asp:TextBox>
<asp:Button ID="btnAddGroup" runat="server" Text="add new group" OnClick="btnAddGroup_Click" />
<asp:Label ID="lblGroup" runat="server"></asp:Label>
<asp:RequiredFieldValidator ID="rfValidatorGroup" ControlToValidate="txtNewGroup" Text="*" InitialValue="<Enter new group here>" Display="Dynamic" runat="server" />
<br />
<asp:ListBox ID="lstGroups" runat="server" CssClass="listbox" AutoPostBack="false" EnableViewState="false"></asp:ListBox>
<br />
<div class="buttonSave" >
<span><asp:Button ID="btnSaveGroup" runat="server" Text="Save" Width="45px" OnClick="btnSaveGroup_Click" /><span>
<span><asp:Button ID="btnEditGroup" runat="server" Text="Edit" Width="45px" /><span>
<span><asp:Button ID="btnDeleteGroup" runat="server" Text="Delete" Width="45px"/></span>
<%--<asp:RequiredFieldValidator runat="server" ID="rfGroupSelect" ControlToValidate="lstGroups" Display="Dynamic" ErrorMessage="Please choose at least one group" /> --%>
</div>
<span><asp:Label ID="lblGroupSaved" runat="server"></asp:Label></span>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Code-Behind
public partial class Admin : System.Web.UI.Page
{
private void Page_Init(object sender, System.EventArgs e)
{
FillListbox(lstGroups);
}
public void FillListbox(ListBox lstGroup)
{
try
{
Fields desGroups = new Fields();
lstGroup.Items.Clear();
lstGroup.DataSource = desGroups.GetGroups();
lstGroup.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public static bool GroupSelected()
{
try
{
return true;
}
catch (Exception Ex)
{
throw Ex;
}
}
[System.Web.Services.WebMethod()]
public static bool DeleteGroup(string aGroup)
{
Fields Group = new Fields();
Group.DeleteGroup(aGroup);
return true;
}
}
Javascript
function btnDeleteGroup_Click()
{
PageMethods.GroupSelected(GroupSelected_Success, GroupSelected_Failure);
}
function GroupSelected_Success(result)
{
if (result)
{
var answer = (confirm("Are you sure you want to delete this information?"))
if (answer)
{
var ind = $get("ctl00_ContentPlaceHolder1_TabContainer_TabField_lstGroups").selectedIndex;
var GroupSelected = $get("ctl00_ContentPlaceHolder1_TabContainer_TabField_lstGroups").options[ind].value;
var lstGroups = $get("ctl00_ContentPlaceHolder1_TabContainer_TabField_lstGroups");
lstGroups.remove(lstGroups.options.selectedIndex);
PageMethods.DeleteGroup(GroupSelected, Items_Success, Items_Failure);
}
else
{
alert("Operation canceled.");
}
}
else
alert("An error occurred.");
}
function GroupSelected_Failure(error)
{
if (error)
alert(error.get_message());
}
function Items_Success(result)
{
if (result)
{
alert("Your operation has been completed.");
}
else
alert("An error occurred.");
}
function Items_Failure(error)
{
if (error)
alert(error.get_message());
} |
Partager