Why does the pop up disappear upon check box click event? - c#

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);
}
}

Related

Why Rowcommand event of a gridview is not getting fired ?

I am facing a kind of weird problem.
Problem:
When I click a link button inside a grid view then RowCommand event of a grid view is getting fired when deployed on a localhost but not when deployed on the IIS i.e. client system. I have also tried a link button inside grid view but that's also not getting fired.
Solution: (Temporary)
When I disabled ValidateRequest on the top of the .aspx page. It worked.
What should I do?
So what can be the possible solution for it? I have googled but nothing good came up.
Code:
<asp:GridView ID="gvAppliedWorks" runat="server" OnRowCommand="gvAppliedWorks_RowCommand" AutoGenerateColumns="false" DataKeyNames="AppliedWorkID, ContractorID" EmptyDataText="No Data Found"
CssClass="table table-responsive table-bordered table-striped" OnRowDataBound="gvAppliedWorks_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Form No">
<ItemTemplate>
<asp:Literal ID="liFormNo" runat="server" Text='<% #Eval("FormNo")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Company Name">
<ItemTemplate>
<asp:Literal ID="liCompanyName" runat="server" Text='<% #Eval("Name")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Financial Bid">
<ItemTemplate>
<asp:Label ID="txtBidAmount" runat="server" CssClass="control-label" Text='<% # string.Format("{0:n2}", Eval("FinancialMoney").ToString())%>' />
%
<asp:Label ID="ddlBidPer" runat="server" CssClass="control-label" Text='<%# Eval("AboveBelow").ToString() %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Awarded Percentage">
<ItemTemplate>
<div class="pull-left">
<asp:HiddenField ID="hdnIsAwarded" Value='<%# Eval("IsAwarded") %>' runat="server" />
<asp:TextBox ID="txtAwardedBid" Text='<%#Eval("AwardedBid")%>' Style="width: 70px !important;" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="pull-left" style="margin-top: 7px">
% <%# Eval("AboveBelow").ToString() %>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remarks">
<ItemTemplate>
<asp:TextBox ID="txtRemarks" Text='<%#Eval("Remarks")%>' runat="server" CssClass="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Award Tender">
<ItemTemplate>
<asp:LinkButton ID="lnkAward" runat="server"
CommandArgument='<%# Eval("AppliedWorkID") %>' CommandName="award"
CssClass="btn btn-sm btn-danger" Enabled='<%# Convert.ToBoolean(Eval("IsBlackList")) == true ? false: true %>'
Visible='<%# Convert.ToBoolean( Eval("IsAwarded"))== false? true:false%>' CausesValidation="false" Text="Award"></asp:LinkButton>
<ajax:ConfirmButtonExtender ID="cbe" runat="server" DisplayModalPopupID="mpe" TargetControlID="lnkAward">
</ajax:ConfirmButtonExtender>
<ajax:ModalPopupExtender ID="mpe" runat="server" PopupControlID="pnlPopup" TargetControlID="lnkAward" OkControlID="btnYes"
CancelControlID="btnNo" BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
Confirmation
</div>
<div class="body">
Are you sure to Award this Work?
</div>
<div class="Popupfooter" align="right">
<asp:Button ID="btnYes" 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>
<asp:TemplateField HeaderText='Action'>
<ItemTemplate>
<asp:LinkButton ID="btnBlackList" runat="server" OnClick="btnBlackList_Click" Visible='<%# Convert.ToBoolean( Eval("IsAwarded"))== false? true:false%>' Enabled='<%# Convert.ToBoolean(Eval("IsBlackList")) == true ? false: true %>' Text='Defective'
CssClass="" ToolTip="Blacklist"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
**.cs**
protected void gvAppliedWorks_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
// GridViewRow gr = ((GridViewRow)((Control)sender).Parent.Parent);
if (e.CommandName == "award")
{
GridViewRow gr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int AppliedWorkID = e.CommandArgument.ToInt32(); //gvAppliedWorks.DataKeys[gr.RowIndex].Value.ToInt32();
TextBox txtAwardedBid = gr.FindControl("txtAwardedBid") as TextBox;
TextBox txtRemarks = gr.FindControl("txtRemarks") as TextBox;
Label txtBid = gr.FindControl("txtBidAmount") as Label;
Label lblAboveBelow = gr.FindControl("ddlBidPer") as Label;
string AboveBelow = lblAboveBelow.Text;
Decimal BidAmount = txtBid.Text.ToDecimal();
if (String.IsNullOrEmpty(txtRemarks.Text))
{
Utility.Msg_Error(this.Master, "Remarks Required!!!");
return;
}
Decimal AwardedBid = string.IsNullOrEmpty(txtAwardedBid.Text.Trim()) ? 0 : txtAwardedBid.Text.Trim().ToDecimal();
string Remarks = txtRemarks.Text;
if (AwardedBid != BidAmount)
{
Utility.Msg_Error(this.Master, "Financial Bid must be equal to Awarded Percentage");
return;
}
if (ClsTender.IsReceivedSubMainOffice(AppliedWorkID, LoginUserID, AwardedBid, Remarks, BidAmount, AboveBelow))
{
Utility.Msg_Success(this.Master, "Work Awarded Successfully!!!");
fill_gvAppliedWorks(labNitNo.Text.Replace("NIT No :", "").ToInt32(), labWorkNo.Text.Replace("Work No :", "").ToInt32());
}
}
}
catch (Exception ex)
{
Utility.Msg_Error(Master, ex.Message);
}
}
It sounds like your page is trying to submit what it thinks is potentially dangerous content if setting the ValidateRequest = false solves the issue. Is it possible that one of the controls on your page is sending html or something like that?
If one of your controls needs to send HTML then you can overcome this by adding an attribute to your model.
[AllowHtml]
[Required]
public string article_content { get; set; }
This will allow html to be entered into the control.

Why doesn't my code access the control inside item template?

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);
}
}

UpdatePanel and panel visibility asp.net c#

I have two panels. Each panel contains an updatepanel.
The first panel is a password Textbox.
I set the second panel's visibility on page_load to false.
If the user enters the correct password, the second panel should be visible and the first panel shouldnd.
The code:
<asp:Panel ID="passwordPanel" runat="server">
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<ContentTemplate>
Geben Sie das Passwort ein:<br />
<br />
<asp:TextBox ID="txtPassword" AutoPostBack="false" runat="server" TextMode="Password"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnConfirmPassword" runat="server" AutoPostBack="true" Text="Senden" CssClass="button" OnClick="btnConfirmPassword_Click"/>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="panelUploadDownload" runat="server">
<h2>Upload Paketformeln CSV</h2>
<input type="file" id="myFile" name="myFile" />
<asp:Button runat="server" ID="btnUpload" OnClick="btnUploadClick" CssClass="button" Text="Upload" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<br />
<asp:Label ID="lblStatus" runat="server" Text="statusLabel"></asp:Label>
<br />
<asp:Panel ID="panelChanges" runat="server" CssClass="pnlCSS">
<asp:Label ID="lblChangesHeader" runat="server" Font-Bold="True" ForeColor="Black" Text="Änderungen"></asp:Label>
<br />
<asp:Label ID="lblChanges" runat="server" ForeColor="#009900" Text="changes"></asp:Label>
<br />
<br />
<asp:Button ID="btnConfirm" runat="server" OnClick="btnConfirm_Click" CSSClass="button" Text="Änderungen bestätigen" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<br />
<br />
<h2>Download Paketformeln CSV</h2>
<p><asp:Button ID="btnDownloadCsv" runat="server" OnClick="btnDownloadCsv_Click" Text="Download CSV" CSSClass="button"/></p>
</asp:Panel>
And the C# code:
protected void btnConfirmPassword_Click(object sender, EventArgs e)
{
if (txtPassword.Text == "XX")
{
uploadDownloadPanel.Visible = true;
passwordPanel.Visible = false;
}
}
Load Event
protected void Page_Load(object sender, EventArgs e)
{
mainController = new MainController();
setStatus("", Color.Black);
lblChanges.Visible = false;
lblChangesHeader.Visible = false;
btnConfirm.Visible = false;
panelChanges.Visible = false;
panelUploadDownload.Visible = false;
}
For some reason it doesnt work. Any clues? Triggers?
The SecureString class doesn't allow you to see the value; that's the whole point of it. If you want to be able to work with the value entered into the PasswordBox, use the Password member of PasswordBox instead of the SecurePassword member:
protected void btnConfirmPassword_Click(object sender, EventArgs e)
{
if (txtPassword.Password == "XX")
{
uploadDownloadPanel.Visible = true;
passwordPanel.Visible = false;
}
}
i just removed the updatepanel from the passwordPanel and it worked.
In your load event, do the following
if(IsPostback)
{
uploadDownloadPanel.Visible = false;
}
Actually, every time when you press button, you load event also triggered
You can set your UpdateMode to Always of update panel within panelUploadDownload panel.It will work.
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" runat="server">

Disable button inside a GridView TemplateField

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;
}

Two popups on a single button with a condition

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();
}

Categories

Resources