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
Solved

PostBack URL not working

Posted on 2009-05-14
11
919 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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