Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cross page Postback

Status
Not open for further replies.

Denster

Programmer
Apr 9, 2001
198
GB
I have a server side button on my web site that looks like this.
<code>
<asp:Button ID="cmdUpdateGame" runat="server" Text="Save Game" PostBackUrl="~/Admin/SaveDetails.aspx" />
</code>

The problem is that when it is pressed the current page refreshes loosing any data that has been entered before entering the page specified in the postbackUrl.
I'm relatavely new to .NET so is there something else I need to do.
 
All I want to do is transfer the details entered on one page to another so they can be updated on the database.
Classic ASP was easy using request.form, how the hell do you accomplish this using .NET!
Everything I have tried so far refreshes the current page and so loses the data that has been entered.
Trying to use the PreviousPage property at the moment but still struggling.
 
Having the same problem. I just created a samiliar thread. I am new to ASP.net also.

It seems that even when a simple button is clicked on a single page the page_load event and all the above are always trigged therefore declaring the same variables and resetting them all the time
 
For simple pages you can check for post back using Page.IsPostBack. However I have other controls on the form that rely on the postback and I cant differentiate which control has been clicked.
 
Why pass the values to another page to update the database? In the button click event, just colled the values of the controls you need to send to the db, call your SQL or Stored Procedure. Then you can display a status message of the Insert/Update.

From your posts, it seems you need some introductory information to get you started.
Try:
 
What I have are 3 buttons on a page that require an update of sort to the database. I also have 2 other cotrols (ComboBoxes) that require auto post back refreshing it with selected items from the combobox.
The comboboxes work fine by checking the page.Isbostback property, however the buttons also postback to the same page before any update is done and therefore loses any data that has been entered.
The button_Click event would be an ideal solution but this again refreshes the page - what is the point of that?
This is now the third day and begining to get a little frustrated by it all.
 
You are losing what data? If you are referring to the comboboxes then you are repopulating on each post back. You need to check page.ispostback in the page_load event.

You will need to post your code and source HTML so we can help you better.
 
The button_Click event would be an ideal solution but this again refreshes the page - what is the point of that?
As jbenson001 said above, you need to read up on the basics of ASP.NET if you don't understand why this happens. These is fundamental knowledge that you will need to have if you are going to be doing any ASP.NET development. Follow the tutorials and video's at the link provided above, as well as researching articles on the ASP.NET page life cycle.



-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
The comboboxes are used to select certain records to populate the textboxes on post back. I'm checking the page.IsPostback so the comboboxes dont get repopulated, only the textboxes.
Like I said the comboboxes work fine.
The problem is the data entered into the textboxes gets lost when a button is pressed, in this instance I dont want the textboxes to repopulate with the original data before it gets saved to the database - which is what is happening.
 
The code is a bit messy with all the experimenting I'v been doing but here it is anyway
Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Game As clsGame
        Dim Course As clsCourse
        Dim nCourseID As Integer
        Dim nYear As Integer
        Dim bLoading As Boolean
        Dim nCurrentGame As Integer
        Dim nGameCount As Integer
        Dim sSaveType As String
        Dim bNewGame As Boolean

        Try
            If Request.QueryString("SaveType") = "Game" Then
                UpdateGame()
            End If

            If Request.QueryString("SaveType") = "Course" Then
                UpdateCourse()
            End If

            If Request.QueryString("SaveType") = "NewGame" Then
                bNewGame = True
            End If

            nCourseID = CInt(Request.QueryString("CourseID"))
            sSaveType = Request.Form("SaveType")

            m_Season = New clsSeason
            m_Game = New clsGame

            If Not Page.IsPostBack Then
                Course = New clsCourse
                Course.Load(nCourseID)
                m_lCourseID.Value = nCourseID
                cboSeason.DataSource = m_Season.YearsPlayed
                cboSeason.DataValueField = "Year"
                cboSeason.DataBind()
                If Session("SelectedYear") <> "" Then
                    cboSeason.Text = Session("SelectedYear")
                Else
                    Session("SelectedYear") = cboSeason.Text
                End If
                txtCourseName.Text = Course.Name
                txtWebSite.Text = Course.Hyperlink
                Course = Nothing
                bLoading = True
            End If

            nYear = CInt(cboSeason.Text)

            m_Season.CurrentYear = nYear
            If m_lCourseID.Value > 0 Then
                m_Season.LoadGames(m_lCourseID.Value)
            End If

            If m_Season.Games.Count > 0 Then
                Game = m_Season.Games.Item(1)

                nGameCount = 0
                lstGames.Visible = True

                If lstGames.SelectedIndex = -1 Then
                    '-1 is used the first time it loads, so set the selected game to 0 for game 1
                    nCurrentGame = 0
                Else
                    'Anything else has been selected from the list
                    nCurrentGame = lstGames.SelectedIndex
                End If
                lstGames.Items.Clear()
                'reset the boxes
                txtDetails.Text = ""
                txtExtraDetails.Text = ""
                txtPrice.Text = "0.00"
                txtImagePath.Text = ""
                txtTitle.Text = ""
                chkLeagueGame.Checked = False
                cboHours.Text = "00"
                cboHours.Text = "00"
                calGame.TodaysDate = Date.Now

                For Each Game In m_Season.Games
                    'Loop through all the games for the selected season
                    lstGames.Items.Add("Game " & nGameCount + 1)


                    If nCurrentGame = nGameCount And Not bNewGame Then
                        'If the game id matches the selected game fill the boxes
                        txtDetails.Text = Game.Details
                        txtExtraDetails.Text = Game.ExtraInformation
                        txtPrice.Text = Game.Price
                        txtTitle.Text = Game.Name
                        txtImagePath.Text = Game.ImageLocation
                        chkLeagueGame.Checked = Game.LeagueGame
                        cboHours.Text = Game.MatchDate.ToString("hh")
                        cboHours.Text = Game.MatchDate.ToString("mm")
                        calGame.TodaysDate = Game.MatchDate
                        calGame.SelectedDate = Game.MatchDate
                        m_GameID.Value = Game.ID
                    End If

                    nGameCount = nGameCount + 1
                Next Game
                lstGames.SelectedIndex = nCurrentGame
                lblNone.Visible = False
                Game = Nothing
            Else
                lblNone.Visible = True
                lstGames.Visible = False
            End If
            m_Season = Nothing

        Catch es As Exception

        End Try
    End Sub

    Protected Sub cboSeason_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboSeason.SelectedIndexChanged
        Session("SelectedYear") = cboSeason.Text
    End Sub

    Protected Sub cmdUpdateGame_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUpdateGame.Click
        Dim context As HttpContext = HttpContext.Current
        Dim dtMatchDate As Date
        Dim sDatePlayed As String
        Dim Game As New clsGame

        dtMatchDate = calGame.TodaysDate

        sDatePlayed = cboSeason.Text & "-" & dtMatchDate.ToString("MM-dd ") _
            & " " & cboHours.Text & ":" & cboMins.Text

        Game.CourseID = m_lCourseID.Value
        Game.DateAsString = sDatePlayed
        Game.Details = txtDetails.Text
        Game.ExtraInformation = txtExtraDetails.Text
        Game.ImageLocation = txtImagePath.Text
        Game.Price = txtPrice.Text
        Game.LeagueGame = chkLeagueGame.Checked
        Game.Name = txtTitle.Text
        Game.ID = m_GameID.Value

        Game.save()

        Game = Nothing
        MsgBox("Update Complete")
    End Sub

To re-iterate the page refreshes on a combobox selection to reload the text boxes with the selected record. I dont want this to happen when a button is clicked. I'v tried using the request.querystring method which works the first time around but keeps hold of this when a combobox is selected. This results in repeating the last button event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top