Click here to Skip to main content
15,899,313 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionRe: Control to insert several numeber at once Pin
amina897-May-10 22:38
amina897-May-10 22:38 
AnswerRe: Control to insert several numeber at once Pin
Peace ON7-May-10 22:46
Peace ON7-May-10 22:46 
QuestionRe: Control to insert several numeber at once Pin
amina897-May-10 23:22
amina897-May-10 23:22 
AnswerRe: Control to insert several numeber at once Pin
Peace ON9-May-10 20:35
Peace ON9-May-10 20:35 
QuestionHow should I create a class that I can access across multiple ASP.NET pages? Pin
Adam Brown 35-May-10 4:26
Adam Brown 35-May-10 4:26 
AnswerRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
Peace ON5-May-10 4:33
Peace ON5-May-10 4:33 
AnswerRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
Sandesh M Patil5-May-10 4:42
Sandesh M Patil5-May-10 4:42 
AnswerRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
overtech065-May-10 4:58
overtech065-May-10 4:58 
Create a class that inherits "System.UI.Web.Page" and put the properties there that you need to be able to access from all pages. Be sure to build your accessors there as well.

All other pages in your web application should inherit from that class. Then the properties you built there will be accessible...

Something like this:

// Page class - myPage.cs
Public class myPage : Page
{
    protected SqlConnection conn;
    protected SqlCommand cmd;

    public myPage() : base()
    {
        string connectionString = ConfigurationManager.ConnectionString["DBConnectionString"].ConnectionString;
        this.conn = new SqlConnection(connectionString);
        this.cmd = new SqlCommand();
        this.cmd.Connection = conn;
    }

    protected int myIntProperty
    {
        // From here you can call your static classes
        get { return CodeLayer.myProperties.myInt; }
        set { CodeLayer.myProperties.myInt = value; }

    }
}


Now when you create a new page in your web application, your page should inherit this class. In this example that would mean that whenever the page loads, you would already have an SqlConnection and SqlCommand object defined and usable and you can access your "myInt" property.

public partial class PageOne : myPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // the SqlConnection and SqlCommand objects are already created
        cmd.CommandText = "SELECT * FROM myTable";
        this.myIntProperty = 10;
    }
}


- Dave
GeneralRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
Adam Brown 36-May-10 3:47
Adam Brown 36-May-10 3:47 
GeneralRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
overtech066-May-10 6:36
overtech066-May-10 6:36 
AnswerRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
T M Gray5-May-10 4:58
T M Gray5-May-10 4:58 
GeneralRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
Adam Brown 36-May-10 3:53
Adam Brown 36-May-10 3:53 
QuestionProblem Pin
MaheshSharma5-May-10 4:21
MaheshSharma5-May-10 4:21 
AnswerRe: Problem Pin
Sandesh M Patil5-May-10 4:24
Sandesh M Patil5-May-10 4:24 
AnswerRe: Problem Pin
JHizzle5-May-10 4:24
JHizzle5-May-10 4:24 
AnswerRe: Problem Pin
Not Active5-May-10 4:57
mentorNot Active5-May-10 4:57 
QuestionRegarding AjaxToolkit. Pin
dayakar_dn5-May-10 3:58
dayakar_dn5-May-10 3:58 
Questionproblem in update panel Pin
souravghosh185-May-10 2:35
souravghosh185-May-10 2:35 
AnswerRe: problem in update panel Pin
Jamil Hallal5-May-10 2:49
professionalJamil Hallal5-May-10 2:49 
AnswerRe: problem in update panel Pin
Abhijit Jana5-May-10 3:10
professionalAbhijit Jana5-May-10 3:10 
GeneralRe: problem in update panel Pin
Not Active5-May-10 3:22
mentorNot Active5-May-10 3:22 
AnswerRe: problem in update panel Pin
Not Active5-May-10 3:21
mentorNot Active5-May-10 3:21 
Questionhow to display properties on sale using google map Pin
Sandesh M Patil5-May-10 2:22
Sandesh M Patil5-May-10 2:22 
AnswerRe: how to display properties on sale using google map Pin
Not Active5-May-10 2:31
mentorNot Active5-May-10 2:31 
GeneralRe: how to display properties on sale using google map Pin
Sandesh M Patil5-May-10 2:43
Sandesh M Patil5-May-10 2:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.