简体   繁体   中英

in code behind find out which page uses an user control

In my application I'm using a usercontrol for two pages: AddInfo.aspx and EditInfo.aspx.

The thing is that I want different thing to happen when saving the info, depending on which page the user is at (ie. what he's actually doing).

So what i'm wondering is if there's any way to use an if statement to find out which page that right now is using the user control? In that case my problem could be solved.

protected void SaveButton_Click(object sender, EventArgs e) {

    if (//The page using the usercontrol = Edit.aspx) {
        // do this...   
    }
    else {
        // do that...   
    }
}

Thanks in advance

protected void SaveButton_Click(object sender, EventArgs e) {

    if (this.Page is EditInfo) {
       // do this...   
    }
    else {
        // do that...   
    }
}

Where EditInfo is your page's class.

You could also define a Behavior property on your user control and set it in your Xaml code according to what you want in which page. This would be a nice way to avoid the need to know where you are.

protected void SaveButton_Click(object sender, EventArgs e) {

    if (Request.Url.AbsoluteUri.Contains("Edit.aspx")) {
       // do this...   
    }
    else {
        // do that...   
    }
}

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