Home > Net >  [for] ASP.NET how to rewrite the parent method
[for] ASP.NET how to rewrite the parent method

Time:09-29

Sorry everybody first a great god, and not much, also please burke,
The problem is such,

Public class memgPage: System. Web. UI. Page
{

Public memgPage ()
{
Enclosing the Load +=new EventHandler (memgPage_Load);
}

Protected void memgPage_Load (object sender, EventArgs e)
{
if (! IsLogin ())
{
Response. Write (" & lt; Script> The parent. The location. Href='https://bbs.csdn.net/topics/login.aspx' & lt;/script>" );
The Response. The End ();
}
}

Private bool IsLogin ()
{
If (Session [" user "]!=null)
{
return true;
}
return false;
}
}


I inherited this class a page

Child pages
Public partial class User_Edit: memgPage
{

//here to handle the login timeout, but the program execution to the upper jump, how to deal with here?
}


Thank you for the

CodePudding user response:

Rewrite the parent class, and asp.net has nothing to do, it's just the basic c # syntax, you need to be familiar with c # inheritance,

Understand the override
Public override ActionResult Index ()
{
}

CodePudding user response:

reference 1st floor daixf_csdn response:
override the parent class, and asp.net has nothing to do, it's just the basic c # syntax, you need to be familiar with c # inheritance,

Understand the override
Public override ActionResult Index ()
{
}
great god, and how are you, I was all before, or an error, just to ask, is this: before
Public override void memgPage_Load (object sender, EventArgs e)
{
}
To quote what I couldn't find any way..., a great god, please grant instruction, just the front turned back end...

CodePudding user response:

Questions to clarify, efficiently solve the problem, also needs to be efficient to ask questions,
Ask a question, I would submit:
1, the problem scenarios, including the operating system, database, technology stack
2, my key code
3, my specific error

What can't find what your "report way... words like", exactly what is wrong? Said so fuzzy is to let you guess? Please put the wrong concrete images or text!

CodePudding user response:

You haven't stick son page code, much less,

CodePudding user response:

 virtual protected void memgPage_Load (object sender, EventArgs e) 
{
if (! IsLogin ())
{
Response. Write (" & lt; Script> The parent. The location. Href='https://bbs.csdn.net/topics/login.aspx' & lt;/script>" );
The Response. The End ();
}
}

CodePudding user response:

To pay attention to the object (class) object instantiation method doesn't inherit, so you wrote
 enclosing the Load +=new EventHandler (memgPage_Load); 
this code is not inherited, so you have to be in subclasses page instantiation method would write it again!!

CodePudding user response:

Asp.net webform will automatically find and invoke several event handling methods of the page, so does not need to be registered in instantiation method (registration will be executed twice),

Are the asp.net, you should determine your need to write the code, the code should be either deleted, or to rewrite it again in the child pages!!!!!

CodePudding user response:

reference daixf_csdn reply: 3/f
problems to clarify, efficiently solve the problem, also needs to be efficient to ask questions,
Ask a question, I would submit:
1, the problem scenarios, including the operating system, database, technology stack
2, my key code
3, my specific error

What can't find what your "report way... words like", exactly what is wrong? Said so fuzzy is to let you guess? Please put the wrong concrete images or text!

Tip: didn't find the right way to rewrite

CodePudding user response:

refer to 6th floor sp1234 response:
to pay attention to, objects (classes) object instantiation method doesn't inherit, so you wrote
 enclosing the Load +=new EventHandler (memgPage_Load); 
this code is not inherited, so you have to be in subclasses page instantiation method would write it again!!
I rewrote the, but every time he performs memgPage_Load page will jump to the parent class, no longer perform the subclass page, a great god, please grant instruction, thank you

CodePudding user response:

refer to 7th floor sp1234 response:
asp.net webform will automatically find and call several event handling methods of the page, so don't need registered in instantiation method (registration will be executed twice),

Are the asp.net, you should determine your need to write the code, the code should be either deleted, or to rewrite it again in the child pages!!!!!
the parent class is written by other colleagues, do not give change, how can child pages, please rewrite the parent class memgPage_Load, let he is not in the parent class jump?

CodePudding user response:

references to the tenth floor OVERSET2 response:
Quote: refer to 7th floor sp1234 response:

Asp.net webform will automatically find and invoke several event handling methods of the page, so does not need to be registered in instantiation method (registration will be executed twice),

Are the asp.net, you should determine your need to write the code, the code should be either deleted, or to rewrite it again in the child pages!!!!!
the parent class is written by other colleagues, do not give change, how can child pages, please rewrite the parent class memgPage_Load, let he is not in the parent class jump?


It will not be able to inherit it, your page again additionally,

In an organization, you may not have the design process, if the design process, the design is very reasonable but still can not perform, then from the organization said that your colleagues should be fired,

CodePudding user response:

Go normal according to the interface, the design of inheritance and implementation process,

"Actually" way of injection can cause bizarre things, cause the effect of a small leak will sink a great ship, so I want to tell you first idea, against random "play technology" design methods,

CodePudding user response:

refer to 12 floor sp1234 reply:
go normal according to the interface, the design of inheritance and execution process,

"Actually" way of injection can cause bizarre things, cause the effect of a small leak will sink a great ship, so I want to tell you first idea, against random "play technology" design mode,
you said yes, a few words, points out the key feeling, thank

CodePudding user response:

Explain your problem
1 level of inheritance memgPage: System. Web. UI. Page
2 secondary succession User_Edit: memgPage

Then the problem clearly, when loading User_Edit page, will go to the superclass constructor initializes the memgPage,
Then instantiated User_Edit constructors, will be the focus of your question, also is the basic knowledge of the concept of inheritance
So the
He ran to the
 public memgPage () 
{
Enclosing the Load +=new EventHandler (memgPage_Load);
}

Protected void memgPage_Load (object sender, EventArgs e)
{
if (! IsLogin ())
{
Response. Write (" & lt; Script> nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related