0

The project contains files of .aspx.cs , .aspx , .htm , .cs etc. As far as I understand, it is a web application project. I am working on a base page named PageBase.cs which includes features that all other pages would inherit from. I want to test how this page works and I am stuck.

There's no "Start Debug" nor "Run" options. The only one I get is "Attach to a Process". When I attached this .cs file to a process, VS shows that debug is ready but no outcomes are shown. I'm not even sure what outcomes I am expecting though so I can only stop debugging. The followings are the links I found in my research, hopefully they would be helpful in some way:

https://msdn.microsoft.com/en-us/library/3s68z0b3.aspx https://msdn.microsoft.com/en-us/library/df5x06h3(v=vs.110).aspx

I know this question is trivial but I am totally new to .Net. Please help.

2 Answers 2

0

Since you've only created a class, you need to have a way to reach that code. Have one of your pages inherit from that class, and make sure that your custom class is wired into the Page Life cycle events properly (Page_Load, Init etc) depending on when you want the code to execute.

Assuming you set up the inheritance properly, and that your debugger is attached to the process, your breakpoints in the class will be hit when you access that page and hit the appropriate stages in the page lifecycle.

Sign up to request clarification or add additional context in comments.

2 Comments

I am not sure what you mean by "your custom class is wired into the Page Life cycle events properly", so I posted what I did below. Could you please have a look at it and see if my custom class is properly added in the page life cycle events?
@Amanda.J It looks like you understood me well enough. By wiring into the Page Life cycle events, I meant that your code needs to be in events that the framework knows how to execute in response to some event. You got it right, because you code is in the OnInit method. Now just have one of your pages inherit from your base class, set your breakpoint in the OnInit method, attach to the process, and you should reach the breakpoint.
0

This is what I did for PageBase.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Test.Lib.Base
{
    public class PageBase : System.Web.UI.Page
    {
        #region Method
        protected override void OnInit(EventArgs e)
        {
            AutocompleteOff();
            base.OnInit(e);
            if (User.Identity.IsAuthenticated)
                ViewStateUserKey = Session.SessionID;
        }
        protected override void AutocompleteOff()
        {
            Page.Form.Attributes.Add("autocomplete", "off");
        }
        #endregion
    }
}

And then for other pages under test folder, (Body.aspx.cs for instance) I added PageBase as the following:

public partial class PostLogin : Lib.Base.PageBase
    {
            # Method
            ...
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.