How can we associate a single codebehind file with two aspx pages.eg. We have two files First.aspx and Second.aspx and we have cs files codebehind.cs in which we want to write code for both files. Then how we will execute this cs file for both of the aspx file\'s events.

Questions by neelamtest

Showing Answers 1 - 5 of 5 Answers

pranitha

  • Feb 6th, 2006
 

Yes we can make it.Just replace the codebehind filename in both the .aspx files and also the inherits class name with the .cs file name and class name.for example if first.aspx ,second.aspx are the two aspx pages and second.aspx.cs is the codebehind file then in the <@ page > tag of the first.aspx file rename the 'codebehind = first.aspx.cs' with 'codebehind = second.aspx.cs' and also Inherits="WebApplication1.first" with Inherits="WebApplication1.second" when we execute this then second.aspx.cs will be executed.

Guest

  • Mar 2nd, 2006
 

the answer stated by pranitha is absolutly right.

  Was this answer useful?  Yes

IS

  • Jan 30th, 2007
 

Why would someone might need to do such a weird things as sharing code behind code for several pages?

  Was this answer useful?  Yes

MAnojDobhal

  • Jun 24th, 2009
 

<%@ Page Language="C#" CodeFile="Codebehind.aspx.cs" Inherits="class name"> on first.aspx
<%@ Page Language="C#" CodeFile="Codebehind.aspx.cs" Inherits="class name"> on second.aspx
then you can associate a single codebehind file with two aspx pages.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions