I have many checkBoxes HTML controls runat server, I want to disable and enable them together.
I've tried to set them in an ASP.Net Panel and set the panel disabled, but they stayed enabled.
Any idea ?
The code
<asp:Panel runat="server" ID="PrivilegesCheckList" >
<input id="adminPrivilegeCheckBox" type="checkbox" runat="server" />
<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Resource, itemAdminPrivilege%>" />
<br />
<input id="accountPrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal2" runat="server" Text="<%$ Resources:Resource, itemAccountManagerPrivilege%>" />
<br />
<input id="employeePrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal3" runat="server" Text="<%$ Resources:Resource, itemEmployeeManagerPrivilege%>" />
<br />
<input id="orgChartPrivilegeCheckBox" type="checkbox" runat="server" clientidmode="Static" />
<asp:Literal ID="Literal4" runat="server" Text="<%$ Resources:Resource, itemOrgChartPrivilege%>" />
</asp:Panel>
Using JavaScript you may do something like this :
var controls = document.getElementById("<%=panel1.ClientID%>").getElementsByTagName("input");
for (var i = 0; i < controls.length; i++)
controls[i].disabled = true;
Note that ASP.Net produces dynamic Id's for server side controls (panel here ) , that tends to use document.getElementById("<%=panel1.ClientID%>") above.
Setting the Panel to disabled would work for asp Controls like CheckBox but not for an input with runat=server. This checkbox is disabled because the panel has Enabled=false:
<asp:Panel ID="Panel1" runat="server" Enabled="false" >
<asp:CheckBox ID="CheckBox1" runat="server" />
</asp:Panel>
You could also easily fix this with jquery (client side):
$('#mypanelClientID input[type=checkbox]').attr('disabled', true);
Related
hello does anyone knows how to enable and disable a hole div content. i have a div that has a celendar and text boxes as well as dropdownlist etc... and i wanted when the user press a button that the content inside the div was disabled, note that i dont want to make them invisible but enable or disable. Now i know i can make each textbox calendar etc.. disabled individually but i was wondering if there is a way to make the hole div content disabled thus saving some line codes and time. thanks here is the code od the content of the div :
<asp:Calendar ID="mtcDataMR" runat="server" onselectionchanged ="mtcDataMR_SelectionChanged" ></asp:Calendar>
<br />
<asp:TextBox ID="txtData" runat="server" ReadOnly="True"></asp:TextBox>
<br />
</fieldset>
<fieldset>
<legend>Filtrar Marcações</legend>
<br />
Nome de Utente<br />
<asp:CheckBox ID="chkFiltroUtente" text=" " runat="server" AutoPostBack="true" OnCheckedChanged="chkFiltroUtente_CheckedChanged" /><asp:TextBox ID="txtFiltrarNomeUtente" runat="server" AutoPostBack="true" OnTextChanged="txtFiltrarNomeUtente_TextChanged" ReadOnly="True" ></asp:TextBox>
<br />
<br />
<fieldset>
<legend>Tipo de Marcações a Mostrar</legend>
<asp:RadioButton ID="rdbConsultas" text="Consultas" runat="server" GroupName="rdb" AutoPostBack="true" OnCheckedChanged="rdbTratamentos_CheckedChanged" />
<asp:RadioButton ID="rdbTratamentos" text="Tratamentos" runat="server" GroupName="rdb" Autopostback ="true" Checked="True" />
</fieldset>
<br />
Nome de Especialista<br />
<asp:CheckBox ID="chkFiltroEspecialista" Text=" " runat="server" /> <asp:DropDownList runat="server" ID="cbxFiltroEspecialista" OnSelectedIndexChanged ="cbxFiltroEspecialista_SelectedIndexChanged" AutoPostBack="true" /> <br />
Local de Tratamento<br />
<asp:CheckBox ID="chkFiltroLocal" Text=" " runat="server" /> <asp:DropDownList runat="server" ID="cbxLocal" OnSelectedIndexChanged ="cbxFiltroLocal_SelectedIndexChanged" AutoPostBack="true" /> <br />
Hora de Inicio<br />
<asp:CheckBox ID="chkFiltroHora" Text=" " runat="server" /> <asp:DropDownList runat="server" ID="cbxFiltroHora" OnSelectedIndexChanged ="cbxFiltroHora_SelectedIndexChanged" AutoPostBack="true" /> <br />
<fieldset>
<legend> Estados a Apresentar</legend>
<asp:CheckBox ID="chkMRSuspensas" runat="server" text="Mostrar Marcações Suspensas" AutoPostBack ="true" OnCheckedChanged="chkMRSuspensas_CheckedChanged"></asp:CheckBox>
<br />
<asp:CheckBox ID="chkMRCanceladas" runat="server" text="Mostrar Marcações Canceladas" AutoPostBack="true" OnCheckedChanged="chkMRSuspensas_CheckedChanged"></asp:CheckBox>
</fieldset>
<asp:Button text="Limpar Filtros" ID="btnFiltroClear" runat="server" OnClick="btnFiltroClear_Click" />
</fieldset>
</div>
btw what im currently using is (on button click)
mtcDataMR.Enabled = False
txtData.Enabled = False
chkFiltroUtente.Enabled = False
rdbConsultas.Enabled = False
rdbTratamentos.Enabled = False
chkFiltroEspecialista.Enabled = False
chkFiltroLocal.Enabled = False
chkFiltroHora.Enabled = False
chkMRSuspensas.Enabled = False
chkMRCanceladas.Enabled = False
btnFiltroClear.Enabled = False
cbxFiltroEspecialista.Enabled = False
cbxLocal.Enabled = False
cbxFiltroHora.Enabled = False
but as you can see there is so much code lines.
You can enable or disable a div. write inside the div runat="server" and id="a id name " . Then you can access the div id in .cs page. Now You can enable or disable.
Example:
.aspx page:
<div runat="server" id="divSearch"> {here you write} </div>
.aspx.cs Page:
divSearch.enable = false; OR divSearch.enable = true;
I have a form containing different required field.
I also have a ValidationSummarywhich will display a pop-up when clicking on the submit button if some required fields are not filled in.
<asp:ValidationSummary runat="server" ID="vsValidationSummary" ValidationGroup="DefaultGroup" DisplayMode="BulletList" ForeColor="Red" ShowMessageBox="true" ShowSummary="false" />
When filling all the fields except one (see below the field) the popup is displayed (OK) but with only the message :
- Required
For other fields there is the name next to "Required"
The field which is failing is the following :
<div class="formFieldLine">
<span class="userFormLabel">
<ab:FormLabel Colon="false" runat="server" AssociatedControlID="ddlSuperstructureType" Text="<%$ Resources:lbSuperstructureType.Text %>" />
</span>
<ab:LabelledDropDownlist ID="ddlSuperstructureType" runat="server" DataSourceID="dsSuperstructureTypes" DataTextField="Text" DataValueField="Value" CssClass="dropdownSTypeBuyBack" />
<asp:CustomValidator ID="cvSuperstructureType" runat="server" ControlToValidate="ddlSuperstructureType" ClientValidationFunction="ddlSelected_Validate" ValidationGroup="DefaultGroup"
CssClass="validatorMessage" ErrorMessage="<%$ Resources:Messages,RequiredField %>" OnServerValidate="ddlSelected_Validate"/>
<br />
</div>
Here is a working field
<div class="formFieldLine">
<span class="userFormLabel">
<ab:FormLabel Colon="false" runat="server" AssociatedControlID="tbLeasingDuration" Text="<%$ Resources:lblLeasingDuration.Text %>" />
</span>
<ab:LabelledTextBox ID="tbLeasingDuration" runat="server" MaxLength="100" />
<asp:RequiredFieldValidator ID="rvfLeasingDuration" ErrorMessage="<%$ Resources:Messages,RequiredField %>" ControlToValidate="tbLeasingDuration" runat="server" ValidationGroup="DefaultGroup" ForeColor="Red" />
<br />
<asp:RangeValidator ID="rvLeasingDuration" Type="Double" ErrorMessage="<%$ Resources:Messages,InvalidNumber %>" ControlToValidate="tbLeasingDuration" ValidationGroup="DefaultGroup" runat="server" MinimumValue="0" MaximumValue="999999999" ForeColor="Red" Display="Dynamic" style="margin-left : 212px;"/>
</div>
Here is a printscreen of the popup :
Instead of passing the mentioned error message,pass the message which you are required to show...
Check your render block - this doesn't look right:
<%$ Resources:Messages,RequiredField %>
Should it be this?
<%= Resources:Messages,RequiredField %>
I have the checkbox seen below,and I want to do something like this
<asp:CheckBox ID="Accept" runat="server">
Accept terms
But I want the to be part of the asp CheckBox, so that I can do something like this:
<asp:CheckBox ID="AcceptCheckBox" runat="server" Text="Accept" terms first" />
Is that possible, and if so, how do you express it?
Using label
You can use the label tag as:
<asp:CheckBox runat="server" ID="AcceptCheckBox" Text="" />
<label for="<%=AcceptCheckBox.ClientID %>">
<a target="_blank" href="terms.html">terms</a> first
</label>
This is the test output: http://jsfiddle.net/5SVDk/1/
Using asp:Label control
From the idea of #richard-deeming we can also use an asp:Label control to avoid the write on page, and the code will be:
<asp:CheckBox runat="server" ID="AcceptCheckBox" Text="" />
<asp:Label runat="server" AssociatedControlID="AcceptCheckBox">
<a target="_blank" href="terms.html">terms</a> first
</asp:Label>
Using the asp:CheckBox only
You can also use the code behind to add the link as:
AcceptCheckBox.Text = "<a target=\"_blank\" href=\"terms.html\">terms</a> first";
and simple
<asp:CheckBox runat="server" ID="AcceptCheckBox" />
all tested and they render the same html
This is working for me
<asp:CheckBox ID="CheckBox1" Text="go to <a href='http://www.yahoo.com'>yahoo</a>" runat="Server" />
<asp:CheckBox ID="Accept" Text='Accept terms' runat="server" />
I am sure that I am missing something really obvious here, but I just can't see it.
I have an update panel with a datalist inside it. Each item of the datalist has a delete button with which I issue the Delete command for the item.
Deletion is a two part process: I first pop up a modal dialogue from codebehind to ask for confirmation, like so:
/// <summary>
/// Manager delete command
/// </summary>
protected void dlKeywordsManager_DeleteCommand(object source, DataListCommandEventArgs e)
{
//Get the subject ID
int keywordID = (int)dlKeywordsManager.DataKeys[e.Item.ItemIndex];
//Remember the keyword ID on the modal popup
hfKeywordID.Value = keywordID.ToString();
btnConfirmationPopupOK.CommandArgument = "Delete";
lblConfirmationPopupMessage.Text = "キーワード「" + e.CommandArgument.ToString() + "」を本当に削除しますか?";
mpConfirmationPopup.Show();
dlKeywordsManager.DataBind();
udpKeywordsManager.Update();
}
This modal popup is also within the update panel so that I can get the label text values refreshed on partial postback.
When the use presses the OK button of the popup I go on to execute:
protected void btnConfirmationPopupOK_Click(object source, EventArgs e)
{
int keywordID = int.Parse(hfKeywordID.Value);
KeywordBLLOperation operationResult;
switch (((Button)source).CommandArgument)
{
case "Delete":
operationResult = keywordsAPI.DeleteKeyword(keywordID);
switch (operationResult.Result)
{
case KeywordBLLOperationResult.Deleted:
lnlNotificationsPopupMessage.Text = "キーワード「" + operationResult.KeywordName + "」を削除しました。";
break;
case KeywordBLLOperationResult.Failed:
lnlNotificationsPopupMessage.Text = "キーワード「" + operationResult.KeywordName + "」の削除に失敗しました。アドミニストレーターにお伝えください。";
break;
}
break;
}
mpNotificationPopup.Show();
dlKeywordsManager.DataBind();
udpKeywordsManager.Update();
}
I have remove a few non-essential lines here for brevity.
And here is the aspx markup to go with the code:
<asp:UpdatePanel ID="udpKeywordsManager" runat="server" Visible="true" UpdateMode="Conditional" >
<ContentTemplate>
<div class="keywordsManagerHeader">
<%--DISPLAY STATISTICS--%>
<asp:CheckBox ID="chkShowUsageStatistics" runat="server" Text="参照回数を表示する" AutoPostBack="true" OnCheckedChanged="chkShowUsageStatistics_CheckedChanged" CssClass="keywordsManagerCheckBoxes" TextAlign="Left" />
<%--DISPLAY ORDER--%>
<span class="keywordsManagerLabel" >並べ替え</span>
<asp:DropDownList ID="ddlKeywordsOrder" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlKeywordsOrder_SelectedIndexChanged" >
<asp:ListItem Text="なし" Value="None" />
<asp:ListItem Text="科目名" Value="Name" />
<asp:ListItem Text="参照回数" Value="Frequency" />
</asp:DropDownList>
<asp:RadioButtonList ID="rdlOrder" runat="server" AutoPostBack="true" RepeatLayout="Flow" RepeatDirection="Horizontal" CssClass="keywordsManagerRadioButtons" Enabled="false" >
<asp:ListItem Text="昇順" Value="Ascending" />
<asp:ListItem Text="降順" Value="Descending" />
</asp:RadioButtonList>
<%--UPDATE PROGRESS INDICATOR--%>
<span style="position: absolute;">
<asp:UpdateProgress ID="udpSubjectsManagerUpdateProgress" AssociatedUpdatePanelID="udpKeywordsManager" runat="server" DisplayAfter="500" DynamicLayout="False" >
<ProgressTemplate>
<img class="updateProgressIndicator" src="~/Library_Images/Animations/ajax_loading.gif" alt="" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
</span>
</div>
<div class="keywordsManagerContainer">
<%--SUBJECTS DATALIST--%>
<asp:DataList ID="dlKeywordsManager" runat="server" DataKeyField="Keyword_ID" DataSourceID="dsBookKeywords" RepeatDirection="Horizontal"
OnItemDataBound="dlKeywordsManager_ItemDataBound" OnDeleteCommand="dlKeywordsManager_DeleteCommand" OnUpdateCommand="dlKeywordsManager_UpdateCommand" OnPreRender="dlKeywordsManager_PreRender" >
<ItemTemplate>
<span id="KeywordInfo" class="keywordsManagerItem" runat="server">
<asp:Label ID="Subject_NameLabel" runat="server" Text='<%# Eval("Keyword_Name") %>' />
<asp:Label ID="Subject_FrequencyLabel" runat="server" Text='<%# " (" + Eval("Frequency") + ")" %>' Visible="false" />
</span>
<%--HOVER MENU PANEL--%>
<asp:Panel ID="pnlKeywordContextMenu" runat="server" CssClass="keywordsManagerPopupMenuOverall">
<div class="keywordsManagerPopupMenuRow" >
<span class="keywordsManagerLabel">科目「</span>
<asp:Label ID="pnlSubjectContextMenu_Subject_NameLabel" runat="server" Text='<%# Eval("Keyword_Name") %>' />
<span class="keywordsManagerLabel">」を参照している文書数:</span>
<asp:Label ID="pnlSubjectContextMenu_Subject_FrequencyLabel" runat="server" Text='<%# Eval("Frequency") %>' />
</div>
<div ID="Book_ISO_NumbersList" class="keywordsManagerBookISONumbersList" runat="server" visible='<%# (string.IsNullOrEmpty(Eval("Book_ISO_Numbers").ToString())) ? bool.Parse("false") : bool.Parse("true") %>' >
<span class="keywordsManagerLabel">文書:</span>
<asp:Label ID="Book_ISO_Numbers_Label" runat="server" Text='<%# Eval("Book_ISO_Numbers") %>' />
</div>
<div class="keywordsManagerPopupMenuSeparator"></div>
<div class="keywordsManagerPopupMenuRow" >
<asp:TextBox ID="Keyword_NameTextBox" runat="server" Text='<%# Eval("Keyword_Name") %>' CssClass="keywordsManagerPopupMenuInput" />
<asp:Button ID="btnEdit" runat="server" Text="編集" CssClass="buttonShortBottom" CommandName="Update" CausesValidation="true" CommandArgument='<%# Eval("Keyword_Name") %>' />
<asp:Button ID="btnDelete" runat="server" Text="削除" CssClass="buttonShort" CommandName="Delete" CommandArgument='<%# Eval("Keyword_Name") %>' />
</div>
</asp:Panel>
<%--HOVER MENU EXTENDER--%>
<asp:HoverMenuExtender ID="hmeKeywordContextMenu" runat="server" TargetControlID="KeywordInfo" PopupControlID="pnlKeywordContextMenu" PopDelay="100" PopupPosition="Right" HoverDelay="100" />
</ItemTemplate>
<SeparatorTemplate>
<span class="keywordsManagerItemSeparator"></span>
</SeparatorTemplate>
</asp:DataList>
</div>
<%--MODAL POPUPS--%>
<%--CONFIRMATION POPUP--%>
<asp:Panel ID="pnlConfirmationsPopup" runat="server" CssClass="modalNotificationOverall" >
<div class="modalNotificationRow">
<asp:Label ID="lblConfirmationPopupMessage" runat="server" Text="" />
</div>
<div class="modalNotificationRow">
<asp:Button ID="btnConfirmationPopupOK" runat="server" Text="はい" CssClass="buttonMediumLong" OnClick="btnConfirmationPopupOK_Click" />
<asp:Button ID="btnConfirmationPopupCancel" runat="server" Text="いいえ" CssClass="buttonMediumLong" />
</div>
<asp:HiddenField ID="hfKeywordID" runat="server" />
<asp:HiddenField ID="hfNewKeywordName" runat="server" />
</asp:Panel>
<%--NOTIFICATION POPUP--%>
<asp:Panel ID="pnlNotificationsPopup" runat="server" CssClass="modalNotificationOverall" >
<div class="modalNotificationRow">
<asp:Label ID="lnlNotificationsPopupMessage" runat="server" Text="" />
</div>
<div class="modalNotificationRow">
<asp:Button ID="btnNotificationsPopupOK" runat="server" Text="OK" CssClass="buttonMediumLong" />
</div>
</asp:Panel>
<%--MODAL POPUP ANCHORS AND MODULES--%>
<%--DELETE CONFIRMATION--%>
<asp:Label ID="lblConfirmationPopupAnchor" runat="server" Text="" />
<asp:ModalPopupExtender ID="mpConfirmationPopup" runat="server" TargetControlID="lblConfirmationPopupAnchor" PopupControlID="pnlConfirmationsPopup" BackgroundCssClass="modalNotificationBackground" CancelControlID="btnConfirmationPopupCancel" />
<asp:Label ID="lblNotificationPopupAnchor" runat="server" Text="" />
<asp:ModalPopupExtender ID="mpNotificationPopup" runat="server" TargetControlID="lblNotificationPopupAnchor" PopupControlID="pnlNotificationsPopup" BackgroundCssClass="modalNotificationBackground" CancelControlID="btnNotificationsPopupOK" />
</ContentTemplate>
There is a lot of markup in there. The structure is as follows: I have a header section with dropdownlist, radiobuttonlist etc. which allows me to specify the sorting of the data (data comes from an object datasource)
The I have the datalist with items. Each item has a hovermenuextender in which I have the buttons to issue the edit and delete comamnds.
The modal popups are also inside the update panel, but outside the datalist, so that they can be updated as required.
My problem is that this works fine as long as the item I delete is not the last item left in the Datalist. If it is the last item the last popup (mpNotificationPopup) doesn't show.
The code executes all the way through, so the lack of items must cause the upadte panel (udpKeywordsManager) not to update?
Any help as to how to get the datalist to update in this case would be most welcome.
Thanks in advance.
Answering my own question. After painfully rebuilding the whole thing I realised that I was setting the visibility of the update panel to false in the OnPreRender event of the datalist when there were no items left. This basically switched off the update panel half-way through refreshing, so the page didn't refresh when the last element was deleted.
Have sorted it by putting a panel in the update panel which contains all the elements inside it except the "no info available" label and just toggle the visibility of that. Apologies for the stupid question, I guess I was having a stupid moment when I wrote this code...
You should show us the aspx-markup as well, but maybe you've used a ModalPopupExtender inside of your UpdatePanel. Try to move the div/Panel that has the ID of the ModalPopupExtender's PopupControlID property outside of your UpdatePanel.
You only have to nest the UpdatePanel inside of the Popup-Control and not around it.
I hope following makes it clearer:
Instead of doing it this way:
<UpdatePanel>
<DataList>
</DataList>
<ModalPopupExtender>
</ModalPopupExtender>
</UpdatePanel>
You should do it this way:
<ModalPopupExtender>
<UpdatePanel>
<DataList>
</DataList>
</UpdatePanel>
<ModalPopupExtender>
Consider this snippet of code...
<form runat="server">
<asp:TextBox runat="server" ID="TextBoxOne" />
<asp:Button runat="server" ID="SubmitOne" OnClick="ButtonOne_Click" />
<hr />
<asp:TextBox runat="server" ID="TextBoxTwo" />
<asp:Button runat="server" ID="SubmitTwo" OnClick="ButtonTwo_Click" />
</form>
I want to group these two sets of controls.
When the user presses ENTER, having filled out TextBoxOne; the ButtonOne_Click event fires. And when the user has typed something into TextBoxTwo and presses enter; the ButtonTwo_Click event gets fired.
The way you would normally do this, is to have form elements surround each of the groups. But this is not possible in ASP.NET. And short of doing some "has-focus"-logic in JavaScript, I'm all out of ideas.
You can use an <asp:Panel runat=server DefaultButton="SubmitOne"> around the pair.
<form runat="server">
<asp:Panel runat="server" DefaultButton="SubmitOne">
<asp:TextBox runat="server" ID="TextBoxOne" />
<asp:Button runat="server" ID="SubmitOne" OnClick="ButtonOne_Click" />
</asp:Panel>
<hr />
<asp:Panel runat="server" DefaultButton="SubmitTwo">
<asp:TextBox runat="server" ID="TextBoxTwo" />
<asp:Button runat="server" ID="SubmitTwo" OnClick="ButtonTwo_Click" />
</asp:Panel>
</form>