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();
}
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.
Code:
<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 code:
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);
}
}
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 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.
Im a rookie on ASP.Net and been stuck for this for a while.
Everytime the index of my dropdown changes i want to fill my repeater with objects.
This works fine, but when im selecting a value in my dropdown that dosent contain any objects the old objects from the last call is still there, i want them to disappear.
I've tried to clear the items from the repeater using Datasource=null and then do a Databind again, but that dosent work.
I think it has with the ItemDataBound event on my repeater.
The ItemDatabound is not called when i select a value in the dropsdownlist that dosent contain any objects.
ItemDataBound CODE:
protected void rptStudentQuestion_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblAnswer = e.Item.FindControl("lblAnswer") as Label;
TextBox tbxAnswer = e.Item.FindControl("tbxAnswer") as TextBox;
Button btnSend = e.Item.FindControl("btnSend") as Button;
if (lblAnswer.Text == "" || lblAnswer == null)
{
lblAnswer.Visible = false;
lblAnswer.Enabled = false;
tbxAnswer.Visible = true;
tbxAnswer.Enabled = true;
btnSend.Enabled = true;
btnSend.Visible = true;
}
else
{
lblAnswer.Visible = true;
lblAnswer.Enabled = true;
tbxAnswer.Visible = false;
tbxAnswer.Enabled = false;
btnSend.Enabled = false;
btnSend.Visible = false;
}
}
}
OnSelectedIndexChanged CODE:
protected void DrpdwnLectureName_SelectedIndexChanged(object sender, EventArgs e)
{
string SelectedLecture = DrpdwnLectureName.SelectedValue;
string user = Server.HtmlEncode(Context.User.Identity.Name).ToString();
using (var client = new WCFReference.SRSServiceClient())
{
var LectureList = client.GetTeacherLecture(user);
foreach (var item in LectureList)
{
if (item.LectureName == DrpdwnLectureName.SelectedValue)
{
var list = client.GetStudentQuestions(item.LectureID, user);
rptStudentQuestion.DataSource = list;
rptStudentQuestion.DataBind();
}
}
}
}
Markup CODE:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DrpdwnLectureName" AutoPostBack="True" runat="server" OnSelectedIndexChanged="DrpdwnLectureName_SelectedIndexChanged"></asp:DropDownList>
<asp:Panel ID="PrintPanel" runat="server">
<asp:Label ID="Label1" runat="server" Text="Gör en .pdf på besvarade frågor"></asp:Label>
<asp:Button ID="btnDoPdf" runat="server" Text="Button" OnClick="btnDoPdf_Click" />
</asp:Panel>
<asp:Repeater ID="rptStudentQuestion" runat="server" OnItemCommand="rptStudentQuestion_ItemCommand" OnItemDataBound="rptStudentQuestion_ItemDataBound">
<ItemTemplate>
<asp:Label ID="lblQuestion" runat="server" Text='<%# Eval("StudentQuestionQuestion") %>'></asp:Label>
<br />
<asp:TextBox ID="tbxAnswer" runat="server" Visible="false"></asp:TextBox>
<asp:Button ID="btnSend" CommandName="SendAnswer" runat="server" Text="Skicka svar" CommandArgument='<%# Eval("StudentQuestionID") %>' />
<br />
<asp:Label ID="lblAnswer" runat="server" Text='<%# Eval("StudentQuestionAnswer") %>' Visible="false"></asp:Label>
<br />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
Updated Code as Requested(Snippet from DrpdwnLectureName_SelectedIndexChanged)
if (item.LectureName == DrpdwnLectureName.SelectedValue)
{
var list = client.GetStudentQuestions(item.LectureID, user);
if (list.Count() > 0)
{
rptStudentQuestion.Visible = true;
rptStudentQuestion.DataSource = list;
rptStudentQuestion.DataBind();
}
else
{
rptStudentQuestion.Visible = false; // In debug it preforms this, but nothing happens.
}
}
This is not a solution, but can solve your update panel updating problem. You can control updatepanel update manually doing this:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:DropDownList ID="DrpdwnLectureName" AutoPostBack="True" runat="server" OnSelectedIndexChanged="DrpdwnLectureName_SelectedIndexChanged"></asp:DropDownList>
<asp:Panel ID="PrintPanel" runat="server">
<asp:Label ID="Label1" runat="server" Text="Gör en .pdf på besvarade frågor"></asp:Label>
<asp:Button ID="btnDoPdf" runat="server" Text="Button" OnClick="btnDoPdf_Click" />
</asp:Panel>
<asp:Repeater ID="rptStudentQuestion" runat="server" OnItemCommand="rptStudentQuestion_ItemCommand" OnItemDataBound="rptStudentQuestion_ItemDataBound">
<ItemTemplate>
<asp:Label ID="lblQuestion" runat="server" Text='<%# Eval("StudentQuestionQuestion") %>'></asp:Label>
<br />
<asp:TextBox ID="tbxAnswer" runat="server" Visible="false"></asp:TextBox>
<asp:Button ID="btnSend" CommandName="SendAnswer" runat="server" Text="Skicka svar" CommandArgument='<%# Eval("StudentQuestionID") %>' />
<br />
<asp:Label ID="lblAnswer" runat="server" Text='<%# Eval("StudentQuestionAnswer") %>' Visible="false"></asp:Label>
<br />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DrpdwnLectureName" />
</Triggers>
</asp:UpdatePanel>
and when you want to update the panel in code, you call: "UpdatePanel1.Update()"
if (item.LectureName == DrpdwnLectureName.SelectedValue)
{
var list = client.GetStudentQuestions(item.LectureID, user);
if (list.Count() > 0)
{
rptStudentQuestion.Visible = true;
rptStudentQuestion.DataSource = list;
rptStudentQuestion.DataBind();
}
else
{
rptStudentQuestion.Visible = false; // In debug it preforms this, but nothing happens.
UpdatePanel1.Update() //This 'force' updatepanel updating
}
}
I have the following gridview control
<asp:Panel runat="server" ID="pnlBeforeSave" Visible="true">
<asp:GridView ID="gvP" runat="server" AutoGenerateColumns="false" AllowPaging="false"
AllowSorting="false" CssClass="list-table" HeaderStyle-CssClass="header">
<Columns>
<asp:TemplateField HeaderText="Action" ItemStyle-Width="20%" HeaderStyle-HorizontalAlign="Center"
ItemStyle-CssClass="unsortable">
<ItemTemplate>
<input id="btnPay" type="button" onclick="javascript:OpenEditPaymentItemDialogPage('<%# Eval("PmtId") %>');"
value="Edit" class="button save" style="width: 80px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
After I save the griview dataset to Database I have to disable the griview.
but btnPay still enabled. I need to do it from code behind
Any idea?
you need to make input type="button" to accessable on code behind side by adding use of RunAt="Server" element
so you code will be like
<ItemTemplate>
<input ruat="server" id="btnPay" type="button" onclick="javascript:OpenEditPaymentItemDialogPage('<%# Eval("PmtId") %>');" value="Edit" class="button save" style="width: 80px" />
</ItemTemplate>
or make use of Asp:Button
<ItemTemplate>
<asp:button ruat="server" id="btnPay" type="button" onClientclick="javascript:OpenEditPaymentItemDialogPage('<%# Eval("PmtId") %>');" value="Edit" class="button save" style="width: 80px" > </asp:button>
</ItemTemplate>
Than make use of RowDataBound event of datagridview and disable button..
you can use,
<asp:Button ID="btnPay" runat="server" OnClick="btnPay_Click" OnClientClick="return confirm('Are you sure?')" Text="Edit" CommandArgument='<%# Eval("PmtId") %>'/>
public void btnPay_Click(object sender, EventArgs e)
{
var button = (Button)sender;
ClientScript.RegisterStartupScript(typeof(Page), "key", "<script>OpenEditPaymentItemDialogPage('" + button.CommandArgument + "');</script>");
}
I am done it.
C#
ScriptManager.RegisterStartupScript(this, this.GetType(), "HidePaymentItemButtons", "javascript:disableAllButtons_PT;", true);
JS
function disableAllButtons_PT() {
var gridViewID = "<%=gvPamentItemsList.ClientID %>";
var gridView = document.getElementById(gridViewID);
var gridViewControls = gridView.getElementsByTagName("input");
for (i = 0; i < gridViewControls.length; i++) {
// if this input type is button, disable
if (gridViewControls[i].type == "submit") {
gridViewControls[i].disabled = true;
}
}
After you save data, put the following code. I have tested. onlcick is disabled.
for (int i = 0; i < gvP.Rows.Count; i++)
{
HtmlInputButton btn = (HtmlInputButton)gvP.Rows[i].FindControl("btnPay");
if (btn != null) btn.Disabled = true;
}