Solved

asp.net VB refresh page after button click

Posted on 2010-09-18
3
919 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
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 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now