Solved

Query string new apporach

Posted on 2011-03-23
4
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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