Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Some one gave me the below code from code project because I wanted to access a Button in my ControlModel.cs from view.aspx. But I'm not sure about declaring a varibale as globally. I already have a web control( protected Web.Controls.Button Btn;) which is in view.File.aspx.designer.cs. Is that what he meant by global variable? I mean in his code which is butctrl.

First declare one variable as object Globaly.

and write in view.cs as--

C#
                  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               
                        }
                  }


Now in ControlModel.cs
u can get butctrl as ur button from view.aspx.
Posted
Updated 21-Nov-11 9:39am
v2
Comments
Sergey Alexandrovich Kryukov 21-Nov-11 15:38pm    
APS.NET? Tag it. Format the code...
--SA
Nikil S 23-Nov-11 14:13pm    
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
http://www.codeproject.com/Questions/288870/Accessing-a-button-in-aspx-from-a-usercontrol

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