Q:

How can do postback using response.redirect?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            ' hdncurrpayperiod.Value = test1.ToString
            hdnPayperiod.Value = test1.ToString
            lblPayPeriodStartDt.Text = test1
        Else
            lblPayPeriodStartDt.Text = hdnPayperiod.Value
        End If

    End Sub

    Private Sub btnnext_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnnext.Click
        ' hdnPayPeriodStartDt.Value = ""

        Dim datenext As Date
        Dim datenextpayperiod As String

        datenext = DateTime.Parse(lblPayPeriodStartDt.Text)
        datenextpayperiod = datenext.Add(New TimeSpan(14, 0, 0, 0)).ToString("MM/dd/yyyy")
        hdnPayperiod.Value = datenextpayperiod
        lblPayPeriodStartDt.Text = hdnPayperiod.Value
        'hdnPayperiod.Value = lblPayPeriodStartDt.Text.ToString
        Response.Redirect("TimeSystem.aspx?PayPeriodStartDate=" + HttpUtility.UrlEncode(hdnPayperiod.Value), False)

    End Sub

This is a user control which has calender with next and previous buttons and a label. I get the initial date from the a user control property on initial load(not postback) and on next button click it adds 14 days and displays on label. Everything is fine until I use response.redirect which is hitting not postback and getting the property value again. How can I avoid this. I have to pass the value of date with 14 days added to it in the url but this happens only once as it is refreshing with property value every time It hits response.redirect. Please let me know if I am not clear

A:

In Page_Load in Not IsPostBack block add another 'if' statement that checks if 'PayPeriodStartDate' is present in query string (Request.QueryString). If it is - use that value to set hidden field and label if it isn't use 'test1' value as in your code sample.

