I have a search button on a filter and when this is clicked I need to show another button. This button goes not trigger a post back so the page doesn't refresh and the button never shows. When the page first loads a bool called DelStatus gets set to true. After I click the search button, if this is true I need to show btnEPODToExcel
. I've tried changing the style, changing the visibility and changing the display from javascript:
protected void btnSearch_Click(object sender, EventArgs e)
{
if (DelStatus == true)
{
btnEPODToExcel.Attributes.Add("style", "display:block");
btnEPODToExcel.Visible = true;
ClientScript.RegisterClientScriptBlock(this.GetType(), "Message",
"<script>$(document).ready(function () { ShowEPODExcel();});</script>");
}
}
JavaScript:
function ShowEPODExcel()
{
document.getElementById('<%= btnEPODToExcel.ClientID %>').style.display= "block";
$('#<%= btnEPODToExcel.ClientID %>').show();
}
Button:
<asp:LinkButton runat="server" ID="btnEPODToExcel" CssClass="btnToExcel" Width="100px" ToolTip="Download Result to Excel" OnClick="btnEPODToExcel_Click" Text="EPODs to Excel" />
are you calling a JS function when btnSearch clicked (Client click) and it returns false..?
if not try to remove btnSearch_Click method and recreate it
If there is no problem about using JQuery, you can try that.
$(document).ready(function () {
$("#btnSearchClick").on('click', function () {
window.alert("Hello");
document.getElementById('btnEPODToExcel').style.display = "block";
$('btnEPODToExcel').show();
return false;
});
});
But it will not postBack simply. If you want to make a postback action, my only advise can be that hold a Session to show or hide this button. Change Session value in btnSearchClick_Click
method and by Session value, set display of button on Page_Load
.
If you don't even get "Hello" alert, probably you made a mistake while adding Javascript to your form.
Assuming that btnSearch_Click is called. I would suggest you to do the following changes to your code.
Button :
<asp:LinkButton runat="server" ID="btnEPODToExcel" style="display:none" Width="100px" ToolTip="Download Result to Excel" OnClick="btnEPODToExcel_Click" Text="EPODs to Excel" />
Code-behind :
if (DelStatus == true)
{
btnEPODToExcel.Attributes.Add("style", "display:block");
}
Hope this helps.
If Nothing works for you than store the value of Delstatus in a hidden field instead of bool and than play with it using javascript. Another way is to try @kalyan Basa answer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.