• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 946
  • Last Modified:

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

0
ITHelper80
Asked:
ITHelper80
  • 6
  • 4
1 Solution
 
MaxOvrdrv2Commented:
it's because you're setting the postback URL programmatically... remember the steps for which .Net generates the code:

PreLoad, Load, any other function calls related to controls, any calls you make, beforeunload, unload...

so it does the page load first here, then assigns the postbackurl, then that's it... done... until you click the button again with it's new postback url, at that point it will handle the call...
0
 
ITHelper80Author Commented:
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?
0
 
MaxOvrdrv2Commented:
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

0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
ITHelper80Author Commented:
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?
0
 
ITHelper80Author Commented:
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

0
 
MaxOvrdrv2Commented:
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!
0
 
MaxOvrdrv2Commented:
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

0
 
ITHelper80Author Commented:
Unfortunatley that will not work for me, the cbATS control is unchecked by default and most of the time will remain unchecked.
0
 
ITHelper80Author Commented:
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?
0
 
prairiedogCommented:
Replace btnSubmit.PostBackUrl = ("~/Submitted Page.aspx") with Response.redirect ("~/Submitted Page.aspx")
Will this work?
0
 
ITHelper80Author Commented:
I had to go with a completely different approach. Thanks for all the suggestions.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now