Solved

Query string new apporach

Posted on 2011-03-23
4
234 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now