0

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

I have already tried btnNext.Enabled=false; it is not working. 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.

2
  • What does this have to do with Classic ASP? Classic ASP and ASP.NET are NOT the same thing - more like distant cousins, at best. Commented Sep 11, 2013 at 6:37
  • I thought may be someone could know the solution. Commented Sep 11, 2013 at 6:41

2 Answers 2

1

I just used the aspx code which you have provided. Note that I don't have the cssClass specified for the buttons.

Now on Submit Button Click Event, I wrote the following code.

btnNext.Visible = false;

And it disables the Button. So, some other factor is creating problems for you.

First of all, try this on a new page without adding any css files. It will work. Then try adding that css files or classes and check if they are creating problems or not.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok Try like below by removing the cssClass... <asp:Button ID="btnNext" name="btnNext" Text="NEXT" ToolTip="Next" runat="server" TabIndex="0" OnClick="btnNext_Click" Enabled="false"/>
You did not get me. I said to remove the cssClass and use <asp:Button ID="btnNext" name="btnNext" Text="NEXT" ToolTip="Next" runat="server" TabIndex="0" OnClick="btnNext_Click" Enabled="false"/> Then in code behind, try btnNext.Visible = false;
Can you post the whole page code by editing the Question? As I suggested before, have you tried on a different page with only these buttons and the code btnNext.Visible = false?
1

You can access the button with it's ID, so you can do something like this:

btnNext.Visible = false;

Have you already tried this?

2 Comments

btnNext.Visible = false; is not working thats why I was trying to use the above code
So instead of Style.Add you should try btnNext.Attributes["style"] = "visibility: hidden";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.