I need to get true or false if bootstrap check-box is checked on server side
This is the control:
<div id="CheckCategoria" runat="server" class="btn-group" data-toggle="buttons-checkbox" runat="server">
<asp:Button ID="ChkInspecao" OnClientClick="return false;" Text="Inspeção" UseSubmitBehavior="False" runat="server" CssClass="btn btn-check" />
<asp:Button ID="ChkHipot" OnClientClick="return false;" Text="Hipot" UseSubmitBehavior="False" runat="server" CssClass="btn btn-check" />
<asp:Button ID="ChkCalibracao" OnClientClick="return false;" Text="Calibração" UseSubmitBehavior="False" runat="server" CssClass="btn btn-check" />
<asp:Button ID="ChkChecagemInterna" OnClientClick="return false;" Text="Checagem Interna" UseSubmitBehavior="False" runat="server" CssClass="btn btn-check" />
<asp:Button ID="ChkRevisao" OnClientClick="return false;" Text="Revisão" UseSubmitBehavior="False" runat="server" CssClass="btn btn-check" />
</div>
as they have runnat="sever", I can get them on server-side but how can I see if it's toggled or not?
I tried:
string Inspecao = ChkInspecao.Attributes["checked"];
but it's returning null.
how can I do that?
You can make beautiful checkboxes with Jquery, please check this page:
ChackBox UI Jquery
Anyway, this is a how:
<script type="text/javascript">
$(function () {
$(".btn").click(function () {
//The old selected gets unselected
$(".Selected").addClass("NoMore");
//This won't
$(this).removeClass("NoMore");
//Because this is the one selected
$(this).addClass("Selected");
//Take the tab selected
$("#ValSel").val($(this).attr("id"));
return false;
});
});
</ script>
<asp:HiddenField ID="ValSel" ClientIDMode="Static" runat="server" />
Then, from code-behind:
Label1.Text = ValSel.Value;
This is the style I used (but it is not important):
<style>
.Selected
{
color:Green;
}
.NoMore
{
color:Red;
}
</ style>
I imagine you would change the background color, but I insist, you can use the checkboxes from the Jquery UI.
Related
I have used panel inside template field and it disappears when I check a checkbox.
I tried fixing it but still disappears. The code works good while debugging but apparently not. Please help if you can. I have spent a lot of time on it already.
<asp:TemplateField HeaderText='Finalized ?'>
<ItemTemplate>
<asp:LinkButton ID="btnFinalizedRecord" OnClick="btnFinalizedRecord_Click" runat="server" Text='<%# Convert.ToBoolean(Eval("IsFinalized")) == true? "Already Finalized": "Finalize" %>'
CssClass="" ToolTip="Finalize" CommandName="Finalize"
CommandArgument='<%#Eval("IsFinalized")%>' Enabled='<%# Convert.ToBoolean(Eval("IsFinalized")) == true? false: true %>'></asp:LinkButton>
<ajax:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" DisplayModalPopupID="mpe2" TargetControlID="btnFinalizedRecord">
</ajax:ConfirmButtonExtender>
<ajax:ModalPopupExtender ID="mpe2" runat="server" PopupControlID="pnlPopup2" TargetControlID="btnFinalizedRecord" OkControlID="btnYes"
CancelControlID="btnNo" BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
<asp:Panel ID="pnlPopup2" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
Confirmation
</div>
<div class="body">
Are you sure to <b>Finalize</b>?
<asp:CheckBox ID="chkConfirmFinalize" runat="server" AutoPostBack="true" OnCheckedChanged="chkConfirmFinalize_CheckedChanged" />
<br />
You will not be able to perform an edit after finalizing.
</div>
<div class="Popupfooter" align="right">
<asp:Button ID="btnYes" Enabled="false" CssClass="btn btn-sm btn-danger" runat="server" Text="Yes" />
<asp:Button ID="btnNo" CssClass="btn btn-sm btn-primary" runat="server" Text="No" />
</div>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
.cs:
protected void chkConfirmFinalize_CheckedChanged(object sender, EventArgs e)
{
try
{
var chkConfirmFinalize = sender as CheckBox;
GridViewRow gr = (GridViewRow)chkConfirmFinalize.NamingContainer;
Panel pnlPopup2 = gr.FindControl("pnlPopup2") as Panel;
if (chkConfirmFinalize.Checked == true)
{
btnYes.Visible = true;
}
else
{
btnYes.Visible = false;
}
pnlPopup2.Visible = true;
}
catch (Exception ex)
{
Utility.Msg_Error(Master, ex.Message);
}
}
With AutoPostBack you are reloading the page (going to the server and back) when the checkbox, that is why the panel disappear.
You should try to use javascript with the "onclick" event.
<asp:CheckBox ID="chkConfirmFinalize" runat="server" OnClick="somefunction(this)" />
And display the button in jquery:
function somefunction(element) {
if ($element.val() == true) {
$("#btnYes").prop('disabled', false);
} else {
$("#btnYes").prop('disabled', true);
}
}
I am working in ASP.Net C#. Trying to invoke Downlaod.aspx page to download a file when a button (added in a gridview) is clicked. Following is code.
<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False"
OnClientClick='<%# String.Format("window.open(""../../Views/Common/Download.aspx?PropertyDocumentID={0}""); return false;", Eval("DocumentId").ToString())%>' />
When i click it, i can see following error in browser console.
Uncaught SyntaxError: Unexpected token .
But I am unable to figure out syntax error.
One option would be to make a separate js function and use it like below:
<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick='OpenWindow(<%# Eval("DocumentId").ToString() %>)' />
JS function:
function OpenWindow(documentId)
{
window.open("../../Views/Common/Download.aspx?PropertyDocumentID=" + documentId);
return false;
}
Try Below:
Method 1:
Change double quote to single quote
<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick = '<%#String.Format("window.open('../../Views/Common/Download.aspx?PropertyDocumentID={0}'); return false;');",Eval("DocumentId").ToString()) %>' />
Or remove your string.Format and use like this
<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick = '<%#" window.open('../../Views/Common/Download.aspx?PropertyDocumentID=" + Eval("DocumentId").ToString() + "); return false;" %>' />
Method 2:
HTML
<asp:Button ID="btnViewDocument" runat="server" Text="View" UseSubmitBehavior="False" OnClientClick='<%# "LocateMyPage(" + Eval("DocumentId").ToString() + ");" %>' />
Javascript
<script type="text/javascript">
function LocateMyPage(DocID){
window.open('../../Views/Common/Download.aspx?PropertyDocumentID=' + DocID);
return false;
}
</script>
I have a multiline textbox with in a asp webforms panel control with a default button to it. I need to submit the form by hitting the Enter (Return) key than going to the next line in textarea. the code is as below:
<asp:Panel ID="pnlChat" runat="server" CssClass="chat-entry" DefaultButton="btnChat">
<p>Type Your Message and Press Enter</p>
<asp:TextBox ID="txtChat" runat="server" CssClass="span12" TextMode="MultiLine" Rows="4"></asp:TextBox>
<asp:Button ID="btnChat" runat="server" Text="Send" CssClass="btn" OnClick="btnChat_Click" />
</asp:Panel>
I tried with the jquery keypress method
$("#<%= txtChat.ClientID %>").keypress(function (e) {
if (e.which == 13) {
// alert('You pressed enter!');
return false;
}
});
But the form is not getting submitted by pressing the enter (return) key. Suggestions/solutions are most welcome.
btw: the panel is inside an updatepanel.
You can have a hidden button outside the UpdatePanel and call that button's click event to submit the form.
In the markup:
...
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" style="display:none" OnClick="btnSubmit_Click" />
In the code:
protected void btnSubmit_Click(object sender, EventArgs e)
{
//Do whatever you need
}
And in the script:
$(document).ready(function () {
$("#<%= pnlChat.ClientID %>").on("keypress","#<%= txtChat.ClientID %>", function(e){
if (e.which == 13) {
var s = $(this).val();
$(this).val(s + "\n");
$("#<%= btnSubmit.ClientID %>").trigger('click');
}
});
});
Although I don't understand why you need to post the whole form when you are using UpdatePanel.
if your Multiline textbox is not working then put your buttons from outside of Update panel. its work perfectly for me. i just put my asp buttons outside of update panel. here is code sample when my multiline textbox text not working.
<td style="float: center; padding-left: 155px;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnPre" OnClientClick="Validate();" ValidationGroup="group1" runat="server"
CssClass="alt_btn" Text="Preview Your Email" OnClick="btnPre_Click" TabIndex="8" />
<asp:Button ID="Continue" OnClientClick="Validate();" ValidationGroup="group1" runat="server"
CssClass="alt_btn" Text="Continue" OnClick="Continue_Click" TabIndex="8" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
and when i put my button from out side of update panel then multiline textbox text updating perfectly.
<td style="float: center; padding-left: 155px;">
<asp:Button ID="btnPre" OnClientClick="Validate();" ValidationGroup="group1" runat="server"
CssClass="alt_btn" Text="Preview Your Email" OnClick="btnPre_Click" TabIndex="8" />
<asp:Button ID="Continue" OnClientClick="Validate();" ValidationGroup="group1" runat="server"
CssClass="alt_btn" Text="Continue" OnClick="Continue_Click" TabIndex="8" />
</td>
I have a modal popup extender which fires on a button click ... now irrespective on the onclientclick function return value true/false its always poping up. I need to stop the modal to fire on return of false and modal to fire the return to true..how to do this?
Please find the code below :
<div style="text-align:center;" runat="server" id="pnlButton">
<asp:Button CssClass="button" ID="btnBack" runat="server" Text="Back"
Width="120px" onclick="btnBack_Click" UseSubmitBehavior="false" />
<asp:Button CssClass="button" ID="btnCancel" runat="server"
Text="Cancel Request" Width="130px" onclick="btnCancel_Click" onClientClick="Validate();" />
</div>
<div style="text-align:center;">
<asp:Button CssClass="button" ID="btnDone" Visible="false" runat="server"
Text="Done" Width="110px" onclick="btnDone_Click" />
</div>
<ajaxToolkit:ConfirmButtonExtender ID="cbe" runat="server"
TargetControlID="btnCancel"
DisplayModalPopupID="ModalPopupExtender1"
ConfirmText="Are you sure you want to click this?" />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnCancel"
PopupControlID="PNL" OkControlID="ButtonOk" CancelControlID="ButtonCancel" BackgroundCssClass="modalBackground" />
<asp:Panel ID="PNL" runat="server" Style="display: none; width: 400px; background-color: White;
border-width: 2px; border-color: Black; border-style: solid; padding: 20px;">
<h2>Are you sure you want to cancel this request?</h2>
<br />
<br />
<div style="text-align: right;">
<asp:Button ID="ButtonOk" runat="server" Text="Yes" CssClass="button" />
<asp:Button ID="ButtonCancel" runat="server" Text="No" CssClass="button" />
</div>
</asp:Panel>
You can open Popup from javascript
function ValidateAndOpen(){
if(Validate()){
var modalDialog = $find("ModalPopupExtender1");
// get reference to modal popup using the AJAX api $find() function
if (modalDialog != null) {
modalDialog.show();
}
}
return false;
}
You must set ClientIDMode="Static" on ModalPopupExtender
and set OnClientClick="return ValidateAndOpen();"
change you code to the following
onClientClick="return Validate();"
Put this script onto your form:
function pageLoad(sender, args) {
if (args.get_isPartialLoad() === false) {
$find("<%= ModalPopupExtender1.ClientID %>").add_showing(function (sender, args) { args.set_cancel(Validate()); });
}
}
I was needing a popup that should be decided with a javascript function. I do not get a popup when i was using the below function. I think am doing a mistake somewhere. Could someone point out what it is?
The save button calls the javascript function
<asp:ImageButton ID="btnSave" runat="server" CausesValidation="true" OnClientClick="isPageValid();return false;" ImageUrl="~/images/green-save.gif"
OnClick="btnSave_Click" TabIndex="22" ValidationGroup="groupProfile" /></td>
function isPageValid()
{
var validated = Page_ClientValidate('groupProfile');
var loccount = document.getElementById('txthiddenloccount').value;
if(validated)
{
if(loccount = "1")
{
var mdlPopup = $find('<%= ModalPopupExtendersavechanges.ClientID %>');
}
else
{
var mdlPopup = $find('<%= ModalPopupExtenderMerchantUpdate.ClientID %>');
}
if(mdlPopup)
{
mdlPopup.show();
}
}
}
<cc1:ConfirmButtonExtender DisplayModalPopupID="ModalPopupExtenderMerchantUpdate" ID="ConfirmButtonExtenderMerchantUpdate"
OnClientCancel="ManageCancel()" runat="server" TargetControlID="btnHidden">
</cc1:ConfirmButtonExtender>
<cc1:ModalPopupExtender ID="ModalPopupExtenderMerchantUpdate" runat="server" BackgroundCssClass="modalBackground"
CancelControlID="btnCancel" PopupControlID="pnlPopupMerchantUpdate" TargetControlID="btnHidden">
</cc1:ModalPopupExtender>
<asp:Button ID="btnYesMerchant" Text ="Yes" runat="server" class="popupButton" causesvalidation="true" OnClientClick="$find('mdlpop').hide(); return true;" onclick="btnYessave_Click"/>
<asp:Button ID = "btnNoMerchant" Text ="No" runat ="server" class="popupButton" causesvalidation="true" OnClientClick="$find('mdlpop').hide(); return true;" onclick="btnNosave_Click"/>
<asp:Button Id="btnCancel" Text ="Cancel" runat="server" class="popupButton" />
And the second is
<cc1:ConfirmButtonExtender DisplayModalPopupID="ModalPopupExtendersavechanges" ID="ConfirmButtonExtendersavechanges"
OnClientCancel="ManageCancel()" runat="server" TargetControlID="btnHidden">
</cc1:ConfirmButtonExtender>
<cc1:ModalPopupExtender ID="ModalPopupExtendersavechanges" runat="server" BackgroundCssClass="modalBackground"
CancelControlID="btnNo" OkControlID="btnYes" PopupControlID="pnlPopupsaveChanges" TargetControlID="btnHidden">
</cc1:ModalPopupExtender>
<asp:Button ID="btnYes" Text ="YES" runat="server" class="popupButton" causesvalidation="true" onclick="btnSave_Click"/>
<asp:Button Id="btnNo" Text ="NO" runat="server" class="popupButton" />
if(loccount = "1")
Looks like we have a problem with the equals sign captain. = != ==
You actually want to show the behavior of the ModalPopupExtender, not the extender itself. Try adding a BehaviorID attribute to each ModalPopupExtender, then use the following JQuery code:
if(loccount == "1")
{
var mdlPopup = $find('ModalPopupExtenderSaveChangesBehaviorID');
}
else
{
var mdlPopup = $find('ModalPopupExtenderMerchantUpdateBehaviorID');
}
if(mdlPopup)
{
mdlPopup.show();
}