ASP.NET disable button at runtime

Hello.
I have a button in a formview that I want to disable at runtime but I cant get it to work.

In my pageload I have:
  Button btnReturn = (Button)fwTest.FindControl("btnReturn");
 if (MyObject.Id == 1)
 {
          btnReturn.Enabled = false;
}

I can debug and see that i passes the line that set it to disabled but it is not disabled
in the browser....
pucko73Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul JacksonSoftware EngineerCommented:
In debug can you see that btnReturn is being set correctly and finding the button and not just returning null.
0
pucko73Author Commented:
Yes i can.
0
Paul JacksonSoftware EngineerCommented:
Please post your complete pageload code and the formview markup.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

pucko73Author Commented:
it seems to work if i put the button on a panel
and add the same code on pnlButtons_PreRender:

All I have in the pageload was the code abowe. (the same code that I moved to pre_render.
No other code that mess with the button.

the button is the last thing inside:
 <asp:FormView ID="fvTest" runat="server" DefaultMode="Edit" DataSourceID="odsVarianceDetails" Width="100%" >
<EditItemTemplate>
some table with labels like:
<asp:Label ID="lblMyLablel" runat="server" Text='<% #Eval("TotalPrice", "{0:C}")%>' Width="120" Style="text-align: right"></asp:Label></td>
and a gridview....
<asp:GridView ID="gvMyGridView" runat="server" DataSourceID="odsMyGridview" AutoGenerateColumns="false" GridLines="None" OnRowDataBound="gvMyGridView_RowDataBound">

and my button:
<asp:Button ID="btnReturn" Text="Return" runat="server" OnClick="btnReturn_Click" />

 

</EditItemTemplate>
0
pucko73Author Commented:
also tried to set it visible false and that did not work either.
0
Paul JacksonSoftware EngineerCommented:
I was going to suggest moving the code to Page_prerendercomplete to see if it worked there, I suggest there is something happing after the Page_Load probably in the fvTest_load that is enabling the control probably something to do with the formview being set into Edit mode.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.