Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "keeping var value" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 21st, 2008, 04:09 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default keeping var value

Morning

ok i am busy with paging my datasource, currently I have previous and next
button, it all works, b ut i want to modify it.

Currently when you click on a button it redirects to the current page and puts
the page number in a querystring, what I want to do is set a 'var' with the page
number, and this works for the first time i click the next button, but when I
click it again, it re-sets the 'var' so basically i can't get past page 2.

how do i keep my var from being re-set, I want it to hold it's value at all times
and allow it to be set with a new value?

make sense?

currently in my BOL i have a params class which will hold parameters.

my params class:
Code:
Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Namespace Keith.ProjectManager.BO

    Public Class Params

        'paging parameters
        Private _activatedpage As Integer 'As Nullable(Of Integer)
        Private _deactivatedpage As Integer 'As Nullable(Of Integer)
        Private _orderby As String '= String.Empty
        Private _activated As String '= String.Empty

        Public Property ActivatedPage() As Integer
            Get
                Return _activatedpage
            End Get
            Set(ByVal value As Integer)
                _activatedpage = value
            End Set
        End Property

        Public Property DeactivatedPage() As Integer
            Get
                Return _deactivatedpage
            End Get
            Set(ByVal value As Integer)
                _deactivatedpage = value
            End Set
        End Property

        Public Property OrderBy() As String
            Get
                Return _orderby
            End Get
            Set(ByVal value As String)
                _orderby = value
            End Set
        End Property

        Public Property Activated() As String
            Get
                Return _activated
            End Get
            Set(ByVal value As String)
                _activated = value
            End Set
        End Property

    End Class

End Namespace
my aspx.vb (only NB bits):
Code:
Imports Keith.ProjectManager.BLL
Imports Keith.ProjectManager.BO
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient

Partial Class view_projects
    Inherits System.Web.UI.Page

    Private CommandNames As String = String.Empty
    Dim pagedData As New PagedDataSource()

'=============================================================================================
    'handles page load events
    Sub Page_Load()
        'add textboxes that need to be cleared by onFocus
        txtSvName.Attributes.Add("onFocus", "Clear(this)")
        txtSvProjectNumber.Attributes.Add("onFocus", "Clear(this)")
        txtSvDescription.Attributes.Add("onFocus", "Clear(this)")

        System.Threading.Thread.Sleep("500")

        'populate projectlist datasource
        If Not IsPostBack Then
            Dim myParams As Params = New Params
            Populate_rpProjectList(myParams)
            Populate_DeactivatedProjects(myParams)
        End If
    End Sub

'=============================================================================================
    'populate and bind rpProjectList datasource
    Sub Populate_rpProjectList(ByVal myParams As Params)
        Dim ProjectsList As New ProjectsList
        'ProjectsList = ProjectsManager.GetList(OrderBy, Activated)

        pagedData.DataSource = ProjectsManager.GetList(myParams.OrderBy, myParams.Activated)
        pagedData.AllowPaging = True
        pagedData.PageSize = 1

        Try
            'pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
            pagedData.CurrentPageIndex = myParams.ActivatedPage
        Catch ex As Exception
            pagedData.CurrentPageIndex = 0
        End Try

        btnPrev.Visible = (Not pagedData.IsFirstPage)
        btnNext.Visible = (Not pagedData.IsLastPage)

        rpProjectList.DataSource = pagedData
        rpProjectList.DataBind()
    End Sub

Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
        'Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & pagedData.CurrentPageIndex - 1)
        Dim myParams As Params = New Params
        myParams.ActivatedPage = pagedData.CurrentPageIndex - 1
        Populate_rpProjectList(myParams)
    End Sub

    Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
        'Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & pagedData.CurrentPageIndex + 1)
        Dim myParams As Params = New Params
        myParams.ActivatedPage = pagedData.CurrentPageIndex + 1
        Populate_rpProjectList(myParams)
    End Sub
Shem
Reply With Quote
Sponsored Links
  #2  
Old July 21st, 2008, 04:39 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

I tend to just use a hidden field on the page
Code:
<asp:hiddenfield id="_cur_page" runat="server" />
Then just set the value property to the current page when the user clicks next or previous. Then you can retrieve the value to know which page to load.

I don't believe variables set in your code behind are included in the viewstate so the value will be reset each time the page is loaded.

There maybe another way, but that's the method I used...
Reply With Quote
  #3  
Old July 21st, 2008, 05:16 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

just tried to use session vars and still they get set back to zero??
how can this be?

Shem
Reply With Quote
  #4  
Old July 21st, 2008, 05:53 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Try using the same instance of myparams throughout the page. Rather than this:-
Code:
        If Not IsPostBack Then
            Dim myParams As Params = New Params
            Populate_rpProjectList(myParams)
            Populate_DeactivatedProjects(myParams)
        End If
Have:-
Code:
Partial Class view_projects
    Inherits System.Web.UI.Page
 
    Private myparams as new Params
    Private CommandNames As String = String.Empty
    Dim pagedData As New PagedDataSource()
.
.
.
.
        If Not IsPostBack Then
            Populate_rpProjectList(myParams)
            Populate_DeactivatedProjects(myParams)
        End If
.
.
.
    Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
        myParams.ActivatedPage = pagedData.CurrentPageIndex - 1
        Populate_rpProjectList(myParams)
    End Sub
 
    Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
        myParams.ActivatedPage = pagedData.CurrentPageIndex + 1
        Populate_rpProjectList(myParams)
    End Sub
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
Shem (July 21st, 2008)
  #5  
Old July 21st, 2008, 06:17 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

found the bugger giving me issues:
Code:
myParams.ActivatedPage = pagedData.CurrentPageIndex + 1
changed it to:
Code:
myParams.ActivatedPage = myParams.ActivatedPage + 1
and now it works a charm
thanks for the help RR

Shem
Reply With Quote
The Following User Says Thank You to Shem For This Useful Post:
richyrich (July 21st, 2008)
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 04:05 PM.



Content Relevant URLs by vBSEO 3.2.0