Solved

PostBack URL not working

Posted on 2009-05-14
11
915 Views
Last Modified: 2012-05-07
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
Comment
Question by:ITHelper80
  • 6
  • 4
11 Comments
 
LVL 10

Accepted Solution

by:
MaxOvrdrv2 earned 500 total points
ID: 24386125
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
 
LVL 6

Author Comment

by:ITHelper80
ID: 24386188
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
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24386249
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 6

Author Comment

by:ITHelper80
ID: 24386674
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
 
LVL 6

Author Comment

by:ITHelper80
ID: 24386711
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
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24386831
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
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24386859
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
 
LVL 6

Author Comment

by:ITHelper80
ID: 24387017
Unfortunatley that will not work for me, the cbATS control is unchecked by default and most of the time will remain unchecked.
0
 
LVL 6

Author Comment

by:ITHelper80
ID: 24387831
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
 
LVL 22

Expert Comment

by:prairiedog
ID: 24390178
Replace btnSubmit.PostBackUrl = ("~/Submitted Page.aspx") with Response.redirect ("~/Submitted Page.aspx")
Will this work?
0
 
LVL 6

Author Comment

by:ITHelper80
ID: 24396956
I had to go with a completely different approach. Thanks for all the suggestions.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 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