Link to home
Start Free TrialLog in
Avatar of GaiaGia
GaiaGiaFlag for United States of America

asked on

How to reload the default web-form page after clicked a Link button for a new tab

Hi gurus,

I developed a simple web app with VB ASP.net.

In Form1 page Main.aspx, I have one Link Button control to open a new tab NewTab.aspx, and have one Button control to go to the next page ThankYou.aspx in the same window.

What happened is, if clicked the Link Button at first to open the NewTab.aspx, and closed the NewTab.aspx window, then click on the Button control in the Main.aspx, trying to go next page ThankYou.aspx, but the Button control will still lead to same content of NewTab.aspx.

I used response.redirect("Main.aspx"), it doesn't work. How to refresh the Main.aspx, after clicked on NewTab.aspx?

Your advise, please!
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Use response.redirect with the url of current page.
use like any below

Response.Redirect("~/MyIntranet/Pages/Default.aspx", false) 
Response.Redirect("~/MyIntranet/Pages/Default.aspx", true) 
or

Response.Redirect("~/MyIntranet/Pages/Default.aspx")

Open in new window


somethimes problem may be due to lack of
lack of a "Handles Me.Load" clause in the Page_load subroutine declaration
Avatar of GaiaGia

ASKER

codecruiser: I did, it still does work. Thanks.

AkilaPalanimuthu: I do have code  "Handles Me.Load" clause in the Page_load  sub declaration. Thanks
>codecruiser: I did, it still does work. Thanks.

You mean it does NOT work? When a response.redirect is encountered, statements after that will be ignored. There is only one response and it can only be redirected to one url.
GalaGia,
Can you share some code?
Avatar of GaiaGia

ASKER

For Link Button Control in the Main.aspx to open a new tab NewTab.aspx:

 <p class="MsoNormal" style="margin: 0in 0in 10pt">
            <span><span>
                                <asp:LinkButton ID="LinkButton1" runat="server" Height="18px" OnClientClick="form1.target ='_blank';"
                        PostBackUrl="~/NewTap.aspx" ToolTip="Click on this link" Width="148px" EnableViewState="False">View the notice</asp:LinkButton></span></span></span></span></p>


For Main.aspx and its Button control to open ThankYou.aspx in the same window:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim FileNumber7 As Decimal = Request.QueryString("Val7")
    End Sub


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


        Dim Username7 As String = Request.QueryString("Val7")
        'Dim FileNumber As Decimal = Request.QueryString("Val7")


        Dim DBconn As New SqlClient.SqlConnection("Data Source=;Initial Catalog=;Integrated Security=True;")
        Dim DBcmd As New SqlClient.SqlCommand
        Dim DBAdap As New SqlClient.SqlDataAdapter
        Dim DS As New DataSet

        DBconn.Open()
        Try
            DBcmd = New SqlClient.SqlCommand("update Temp_ set EnglishCheckbox =@eCheckbox, SpanishCheckbox=@sCheckbox, OtherLanguageCBox=@oCheckbox, languageName=@LanguageName,Signiture=@Signiture,SignitureDate = getdate() where [Number] =@FileNumber ", DBconn)
            DBcmd.Parameters.Add("@eCheckbox", SqlDbType.VarChar).Value = CheckBox1.Checked
            DBcmd.Parameters.Add("@sCheckbox", SqlDbType.VarChar).Value = CheckBox2.Checked
            ...........................
............................
.................................
            DBcmd.Parameters.Add("@FileNumber", SqlDbType.Float).Value = Request.QueryString("Val7")
            DBcmd.ExecuteNonQuery()
        Catch exp As Exception
            Response.Write(exp)
        End Try
        DBcmd.Dispose()
        DBconn.Close()
        DBconn = Nothing

        Response.Redirect("ThankYou.aspx?valfinal=" + Username7)

        ' End Sub
    End Sub
Avatar of GaiaGia

ASKER

I placed the line inside of the subroutine of Button1_Click, it just didn't work:

Response.Redirect("~Main.aspx")
>Response.Redirect("ThankYou.aspx?valfinal=" + Username7)
>Response.Redirect("~Main.aspx")

Which page you actually want to redirect to?
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GaiaGia

ASKER

guru_sami: it works now. Thanks a lot.

codeCruiser: in my page Main.aspx, there is a Botton control and a Link Button control. if click on the Link button, it should lead to a new tab NewTab.aspx, if click on the Button, it should open the Thankyou.aspx in the same window.