Solved

Query string new apporach

Posted on 2011-03-23
4
239 Views
Last Modified: 2012-05-11
Hi

I was reading one article on

http://www.codeguru.com/csharp/.net/net_framework/article.php/c18527/Top-6-Ways-to-Improve-Your-NET-Framework-Code.htm

In the code "Eliminate Duplicate Code" subsection I am not able to get how we can use that approach in my web application. Can anyone please elaborate it more detail.


Regards
Karan Gupta
0
Comment
Question by:KaranGupta
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
jkofte earned 333 total points
ID: 35204788
it is trying to say do not use the same code and controls in that code to get OrganizationId everywhere in your app.

define it as a property in the page if you use it often.
0
 

Author Comment

by:KaranGupta
ID: 35205191
My question is I have define a class inherited from page class. How to use it in any of the webform
0
 
LVL 5

Assisted Solution

by:karthitron
karthitron earned 167 total points
ID: 35205603
Ok, now you have a class (say, AdminPageBase) inherited from System.Web.UI.Page class and in this class you have getOrganisationID() method or required common methods using across pages.

Then in your web form pages, where ever you need this method, just inherit you new class instead of System.Web.UI.Page class. i.e,

Earlier: your pages (say, Detault.aspx) use:
public partial class Default1 : System.Web.UI.Page
  {
//
}

Hereafter your page will be:
public partial class Default1 : AdminPageBase
  {
//So now you can call the getOrganisation() method and in all this type of pages which inherit your class AdminPageBase , which has the method getOrgranisation() or your common methods.
}
0
 
LVL 9

Assisted Solution

by:jkofte
jkofte earned 333 total points
ID: 35206499
in short words you will define a class which is inherited from web.ui.page in appcode folder.

then inherit the page from that class.

and make the definitions which will commonly in that class.

so when you inherit all your pages from that class you will be able to reach them by writing the code only once.

VB Sample:

Imports Microsoft.VisualBasic
Imports System.Data

Public Class BasePage
    Inherits Web.UI.Page
    Protected DataObj As New cData
    Protected Utility As New cUtility

    Dim _ArticleId As Integer = 0

    Public Property ArticleId() As Integer
        Get
            If (Request.QueryString("ArticleId") IsNot Nothing) Then
                If Integer.TryParse(Request.QueryString("ArticleId"), 0) Then
                    _ArticleId = CType(Request.QueryString("ArticleId"), Integer)
                Else
                    _ArticleId = 0
                End If
            Else
                _ArticleId = 0
            End If
            Return _ArticleId
        End Get
        Set(ByVal value As Integer)
            _ArticleId = value
        End Set
    End Property

End Class

Open in new window


And in your pages:


Partial Class _Default
    Inherits BasePage
    Private _ArticleId As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Me.ltrPages.Text = ""
            Me.ltrWarning.Text = ""
            Me.rptArticles.DataBind()
        End If
    End Sub
End Class

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question