Tuesday, 10 September 2013

setting attributes or css of button in code behind in aspx

setting attributes or css of button in code behind in aspx

here is my aspx code for buttons
<div id="navigationButtons">
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_Click" CssClass="button submit"
Enabled="true" />
<asp:Button ID="btnNext" name="btnNext" Text="NEXT"
ToolTip="Next" runat="server" CssClass="button next"
TabIndex="0" OnClick="btnNext_Click" Enabled="false"/>
<asp:Button ID="btnPrev" Text="PREV" ToolTip="Previous"
runat="server" CssClass="button prev" TabIndex="2"
OnClick="btnPrev_Click" Enabled="true"/>
<asp:Button ID="btnExit" Text="EXIT" ToolTip="Exit"
runat="server" CssClass="button exit" TabIndex="3"
OnClick="btnExit_Click" />
</div>
I am unable to change the attributes from code behind so I browsed for the
solution and some blogs suggested using following code in the code behind.
((System.Web.UI.HtmlControls.HtmlElement)Page.Form.FindControl("btnNext")).Style.Add("visible",
"false");
but when I use it there is null exception error in the code. I don't know
how to fix this in the above code behind. Any solution is appreciated.
thanks.

No comments:

Post a Comment