Monday, May 20, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
85
rated 0 times [  90] [ 5]  / answers: 1 / hits: 66547  / 10 Years ago, fri, february 28, 2014, 12:00:00

I am working on asp.net web application.
In one Page I have two asp buttons.
I want to display them in one condition otherwise I don't want to display them.
So I'm trying to do the same like this. But Its not working.
I can't find the reason behind it. Please tell me where is the issue.



To Hide Buttons



if (!IsPostBack)
{
ButtonReplaceId.Style.Add(display, none);
ButtonAssociateRules.Style.Add(display, none);
}


To display buttons



protected void ApplyAssociation(object sender, EventArgs e)
{
//Some piece of code
if(a==0)
{
ButtonAssociateRules.Style.Add(display, block);
ButtonReplaceId.Style.Add(display, block);
}

}


aspx for buttons



    <div style =padding-left:400px;>
<asp:Button ID=ButtonAssociateRules runat=server OnClick=AssociateMultipleRulesButtonClick
CssClass=search_button_in_vm_intersection Text=Associate Multiple Rules
OnClientClick=return OnClientClickAssociateRewardRuleFile(); />

<asp:Button ID=ButtonReplaceId runat=server OnClick=ApplyReplaceIfRuleIntersects
CssClass=search_button_in_vm_intersection Text=Replace Previous Rules
OnClientClick=return OnClientClickReplaceRewardRuleFile(); />

</div>


aspx of button for OnClick event ApplyAssociation()



<asp:UpdatePanel runat=server UpdateMode=Conditional>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=Button1 EventName=Click />
</Triggers>
<ContentTemplate>
<asp:Table runat=server CssClass=rule_file_whole BorderWidth=0 Style=padding-top: 30px;>
<asp:TableRow ID=MerchantRowAssociation HorizontalAlign=Center>
<asp:TableCell>
<div style=text-align: center>
<asp:Button ID=AssociationMerchant Text=Apply Association runat=server OnClick=ApplyAssociation
CssClass=search_button_in_vm_associate1 OnClientClick=return checkValidation() />
</div>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>

More From » c#

 Answers
12

Seeing as you are using a conditional update panel, you can try either of these after putting the buttons inside an update panel.



    protected void ApplyAssociation(object sender, EventArgs e)
{
//Some piece of code
if (a == 0)
{
ButtonAssociateRules.Style[visibility] = hidden;
ButtonReplaceId.Style[visibility] = hidden;
myUpdatePanel.Update();
}
}
protected void ApplyAssociation(object sender, EventArgs e)
{
//Some piece of code
if (a == 0)
{
ButtonAssociateRules.Visible = false;
ButtonReplaceId.Visible = false;
myUpdatePanel.Update();
}
}


Here's an example of your buttons inside an update panel.



<asp:UpdatePanel ID=myUpdatePanel runat=server UpdateMode=Conditional>
<ContentTemplate>
<div style=padding-left:400px;>
<asp:Button ID=ButtonAssociateRules runat=server OnClick=AssociateMultipleRulesButtonClick
CssClass=search_button_in_vm_intersection Text=Associate Multiple Rules
OnClientClick=return OnClientClickAssociateRewardRuleFile(); />
<asp:Button ID=ButtonReplaceId runat=server OnClick=ApplyReplaceIfRuleIntersects
CssClass=search_button_in_vm_intersection Text=Replace Previous Rules
OnClientClick=return OnClientClickReplaceRewardRuleFile(); />
</div>
</ContentTemplate>
</asp:UpdatePanel>

[#72243] Thursday, February 27, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
patienceannel

Total Points: 674
Total Questions: 101
Total Answers: 101

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
patienceannel questions
Fri, Mar 11, 22, 00:00, 2 Years ago
Tue, Oct 20, 20, 00:00, 4 Years ago
Wed, Jul 24, 19, 00:00, 5 Years ago
;