简体   繁体   中英

access click event and control of aspx page from class in asp.net c#

I am using asp.net and have some page that uses the same code behind in .cs I want to move this code like events to separate class how I can access page control and event click in .aspx from class? (I use the property for now)

this is link aspx: Link

aspx.cs : Link

class.cs Link

I came across this problem as well. You have to define your current page in load.

protected void Page_Load(object sender, EventArgs e)
    {
        Page page = new Page(); //I think it is Page control. I am not sure right now, I dont have access to the code I made for that right now. But you propably get the main idea.
        page=this;
        Label c = new Label();
        c= Label1; //Might be c= this.Label1      
    } 

and then from class you can do:

page.c.Text="I found you";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM