Solved

PostBack URL not working

Posted on 2009-05-14
11
908 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now