Link to home
Start Free TrialLog in
Avatar of ITHelper80
ITHelper80

asked on

PostBack URL not working

The below code is suppose to activate the a postback call however its not working unless I submit the form twice...I cant figure it out.

Ive watched the code in debug and it hits the postback command on the first submit but doesnt perform the action.
If cbATS.Checked = True Then
                '## Calls ATS Subroutine ##
                ATS()
                If StopFlag = "Y" Then
                    Exit Sub
                End If
            btnSubmit.PostBackUrl = ("~/Submitted Page.aspx")
        End If
 
                '## Calls Eaton Subroutine ##
        If cbATS.Checked = False Then
            Eaton()
            If StopFlag = "Y" Then
                Exit Sub
            End If
            btnSubmit.PostBackUrl = ("~/Submitted Page.aspx")
        End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of MaxOvrdrv2
MaxOvrdrv2

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 ITHelper80
ITHelper80

ASKER

This code is on my Submit button click event, so the page load wouldnt matter correct?

How can I only activate the postback if my Flag condition is false?
no that's what i mean... because it`s in the submit click event, it won't fire off on to the proper URL until the second click, because on the first click, it`s not present!

you'll need to put something in the page load to handle this... or else this will never work on the first try...
page load:
 
if me.IsPostBack=true then
if sender.id="SubmitButton" then
       If cbATS.Checked = True Then
                '## Calls ATS Subroutine ##
                ATS()
                If StopFlag = "Y" Then
                    Exit Sub
                End If
            btnSubmit.PostBackUrl = ("~/Submitted Page.aspx")
        End If
 
                '## Calls Eaton Subroutine ##
        If cbATS.Checked = False Then
            Eaton()
            If StopFlag = "Y" Then
                Exit Sub
            End If
            btnSubmit.PostBackUrl = ("~/Submitted Page.aspx")
        End If
end if
end if

Open in new window

Thanks for the help...Im trying your code but it doesnt seem to be working.

The submit button's ID = btnSubmit so I am using sender.ID = "btnSubmit"
however when I step through the code (after clicking on submit) it see that IF statement as False and doest execute the code below it....do I need to add something else?
Here is my page load and submit events if it helps any.
Page Load Event
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        If Not Page.IsPostBack Then
            PageSubLoad()
        End If
 
        If Page.IsPostBack Then
            If sender.ID = "btnSubmit" Then
                If StopFlag = "Y" Then
                    Exit Sub
                Else
                    btnSubmit.PostBackUrl = ("~/Submitted Page.aspx")
                End If
            End If
 
 
        End If
    End Sub
_______________________________________________________________________
Submit Button Event
   Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
 
        '## Used for Custom validator on Employee Number Field ##
        If cbATS.Checked = False And txtEmpName.Text = "" Then
            Exit Sub
        End If
 
        If cbATS.Checked = True Then
            '## Calls ATS Subroutine ##
            ATS()
        End If
 
        '## Calls Eaton Subroutine ##
        If cbATS.Checked = False Then
            Eaton()
        End If
    End Sub

Open in new window

ok... yeah that probably won`t work as the sender is the page, not the control... ok... here's what you do, for your CheckBox cbATS, put AutoPostBack=true, and in the routine for the autopostback, this is where you should set your btnSubmit postbackURL... that should work that way when they click on the button the postback url will already be set!
this should set the postback URL at the right point in time for your solution...
postback routine for the CheckBox ATS:
 
 If cbATS.Checked = True Then
                '## Calls ATS Subroutine ##
                ATS()
                If StopFlag = "Y" Then
                    Exit Sub
                End If
            btnSubmit.PostBackUrl = ("~/Submitted Page.aspx")
        End If
 
                '## Calls Eaton Subroutine ##
        If cbATS.Checked = False Then
            Eaton()
            If StopFlag = "Y" Then
                Exit Sub
            End If
            btnSubmit.PostBackUrl = ("~/Submitted Page.aspx")
        End If
 
end postback routine

Open in new window

Unfortunatley that will not work for me, the cbATS control is unchecked by default and most of the time will remain unchecked.
The reason why I am doing a postback URL is to capture the values from the user to display on the second page...is there a better/easier way?
Replace btnSubmit.PostBackUrl = ("~/Submitted Page.aspx") with Response.redirect ("~/Submitted Page.aspx")
Will this work?
I had to go with a completely different approach. Thanks for all the suggestions.