Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
There is a button in vew.aspx page. I want to access that button in my ControlModel.cs. but they both have no knowledge of each other . How can I access the button in my Control class. Some one gave a solution already but it didn't work.

and the button is available in view.aspx.cs.

can i use the FindControl() method to find the button in my control.if so How do i use it. I put 5 days already on this nothing worked please help.

How do i get back to you if i still have questions after you answered my questio?.

please ask me for furthe clarification if you don't get my question.
Posted
Comments
[no name] 23-Nov-11 13:21pm    
"Some one gave a solution already but it didn't work"
What was this solution?
Why didn't FindControl work? Show what you have tried.
rajh7 23-Nov-11 15:56pm    

This is what he gave me a s a solution

object b;
object but;

foreach(object b in this.Controls())
{
if (TypeOf(b) == Button)
{
but Button = CType(b, Button);
// here pass but to global variable. if ur variable is butctrl then
butctrl=but
}
}
Nikil S 23-Nov-11 14:17pm    
Re-post: You would have put your query in the original post itself. And if you want to get back with further clarification, use the "Have a Question or Comment?" option in the original post.
http://www.codeproject.com/Questions/287439/How-to-access-a-button-in-my-control-cs
Nitesh Kejriwal 23-Nov-11 15:13pm    
Explan more on what you want to achieve with getting button in ControlModel.cs
rajh7 23-Nov-11 15:54pm    
I want to access the button in the controlmodel.cs and i want to disable it based on a condition whic is done in controlmodel.cs.

1 solution

1) If you want to react to the button click in the user control, then use the click event of the page to propogate the click to the user control.

2) If you want to set the state of the button based on something that happens in the user control, then your best bet would be to handle a custom event from the user control that can be consumed by the parent page, or if this is a postback event, expose a property or two to get information in the page that is relevant and deal with the button at that level.

At no time should the usercontrol be attempting to modify something on the parent page directly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900