Solved

Query string new apporach

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

943 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

10 Experts available now in Live!

Get 1:1 Help Now