Solved

PostBack URL not working

Posted on 2009-05-14
11
925 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 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