?
Solved

Query string new apporach

Posted on 2011-03-23
4
Medium Priority
?
245 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 1332 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 668 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 1332 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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