Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

asp.net VB refresh page after button click

Posted on 2010-09-18
3
Medium Priority
?
956 Views
Last Modified: 2012-06-27
On my page I am updating a record on button click. But the page is not reloading itself, so after updating it will still display the old contents. What can I add to the code below to make the page reload after updating the db?

Thanks

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim fileName As String = "countdown_bg.png"
        If FileUpload1.HasFile Then
            ' = FileUpload1.FileName
            FileUpload1.SaveAs(MapPath("images/" & fileName))
            Message.Text = "Upload complete."
        Else
            Message.Text = "No files uploaded."
        End If

        Dim LinkID As Integer = 1
        Dim conn_update_link As SqlConnection
        Dim comm_update_link As SqlCommand
        Dim connectionString_update_link As String = _
        ConfigurationManager.ConnectionStrings( _
        "play3on3").ConnectionString
        conn_update_link = New SqlConnection(connectionString_update_link)
        comm_update_link = New SqlCommand( _
        "UPDATE countdown SET year= @year WHERE id = @LinkID", conn_update_link)
        comm_update_link.Parameters.Add("@LinkID", Data.SqlDbType.Int)
        comm_update_link.Parameters.Item("@LinkID").Value = LinkID
        comm_update_link.Parameters.Add("@year", Data.SqlDbType.Int)
        comm_update_link.Parameters.Item("@year").Value = ddlYear.SelectedItem.Value
        Try
            conn_update_link.Open()
            comm_update_link.ExecuteNonQuery()
        Catch
            Message.Text = _
            "Error updating the database.<br />"
        Finally
            conn_update_link.Close()
        End Try

    End Sub
0
Comment
Question by:elliottbenzle
[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
3 Comments
 
LVL 30

Expert Comment

by:Reza Rad
ID: 33710507
what is your page_load method content?
0
 
LVL 4

Author Comment

by:elliottbenzle
ID: 33710642
Protected Sub Page_Load_Slides(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim conn_slides As SqlConnection
        Dim comm_slides As SqlCommand
        Dim reader_slides As SqlDataReader
        Dim connectionString_slides As String = _
        ConfigurationManager.ConnectionStrings( _
        "play3on3").ConnectionString
        conn_slides = New SqlConnection(connectionString_slides)
        comm_slides = New SqlCommand( _
        "SELECT slide " & _
        "FROM slides_side ", conn_slides)
        Try
            conn_slides.Open()
            reader_slides = comm_slides.ExecuteReader()
            If reader_slides.Read() Then
                slide1.ImageUrl = "slides/" & reader_slides.Item("slide").ToString()
                reader_slides.Read()
                slide2.ImageUrl = "slides/" & reader_slides.Item("slide").ToString()
                reader_slides.Read()
                slide3.ImageUrl = "slides/" & reader_slides.Item("slide").ToString()
                reader_slides.Read()
                slide4.ImageUrl = "slides/" & reader_slides.Item("slide").ToString()
                reader_slides.Read()
                slide5.ImageUrl = "slides/" & reader_slides.Item("slide").ToString()

            End If
            reader_slides.Close()
        Catch
        Finally
            conn_slides.Close()
        End Try
    End Sub
0
 
LVL 8

Accepted Solution

by:
Mohit Vijay earned 2000 total points
ID: 33710892
My Suggestion will be:

Create a function, that fetch data from data base (I mean whatever you are doing on page load), so that function will also be called from page load and also be called after you have updated record in databse on button click.

Let me try to explain you how (I am providing just structure, please modify it according to you best needs)

=================Page Load Event=====================

Protected Sub Page_Load_Slides(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.ispostback = false then
FetchDataFromDatabase()
end if
End Sub
==================================================

================Function FetchDatafromDatabase() =====================

private sub FetchDataFromDatabase()
Dim conn_slides As SqlConnection
        Dim comm_slides As SqlCommand
        Dim reader_slides As SqlDataReader
        Dim connectionString_slides As String = _
        ConfigurationManager.ConnectionStrings( _
        "play3on3").ConnectionString
        conn_slides = New SqlConnection(connectionString_slides)
        comm_slides = New SqlCommand( _
        "SELECT slide " & _
        "FROM slides_side ", conn_slides)
        Try
            conn_slides.Open()
            reader_slides = comm_slides.ExecuteReader()
            If reader_slides.Read() Then
                slide1.ImageUrl = "slides/" & reader_slides.Item("slide").ToString()
                reader_slides.Read()
                slide2.ImageUrl = "slides/" & reader_slides.Item("slide").ToString()
                reader_slides.Read()
                slide3.ImageUrl = "slides/" & reader_slides.Item("slide").ToString()
                reader_slides.Read()
                slide4.ImageUrl = "slides/" & reader_slides.Item("slide").ToString()
                reader_slides.Read()
                slide5.ImageUrl = "slides/" & reader_slides.Item("slide").ToString()

            End If
            reader_slides.Close()
        Catch
        Finally
            conn_slides.Close()
        End Try
End Sub

=============Button Click Event================

 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim fileName As String = "countdown_bg.png"
        If FileUpload1.HasFile Then
            ' = FileUpload1.FileName
            FileUpload1.SaveAs(MapPath("images/" & fileName))
            Message.Text = "Upload complete."
        Else
            Message.Text = "No files uploaded."
        End If

        Dim LinkID As Integer = 1
        Dim conn_update_link As SqlConnection
        Dim comm_update_link As SqlCommand
        Dim connectionString_update_link As String = _
        ConfigurationManager.ConnectionStrings( _
        "play3on3").ConnectionString
        conn_update_link = New SqlConnection(connectionString_update_link)
        comm_update_link = New SqlCommand( _
        "UPDATE countdown SET year= @year WHERE id = @LinkID", conn_update_link)
        comm_update_link.Parameters.Add("@LinkID", Data.SqlDbType.Int)
        comm_update_link.Parameters.Item("@LinkID").Value = LinkID
        comm_update_link.Parameters.Add("@year", Data.SqlDbType.Int)
        comm_update_link.Parameters.Item("@year").Value = ddlYear.SelectedItem.Value
        Try
            conn_update_link.Open()
            comm_update_link.ExecuteNonQuery()
        Catch
            Message.Text = _
            "Error updating the database.<br />"
        Finally
            conn_update_link.Close()

FetchDataFromDatabase()
        End Try

    End Sub
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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

688 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