Button Click Causes PostBack = True

TheWizardofInt

Well-known member
Joined
Dec 31, 1969
Messages
333
Location
Orlando, FL
I use the postback method to force users to access through the login page. such that if postback = true, then you go to the login page

Clicking any of the button forms sends the asp code to the page_load event, and the postback = true, so it wants to force the whole thing to reload from log in

What am I doing wrong? Or is there a way to detect that I have clicked the button and then not go to the log in?

Thanks!
 
Im not sure I understand what you mean... The whole point of
PostBack being true is so that you know the user pressed a
button on the form and you can act accordingly. Maybe you should
be checking if PostBack is False, instead?
 
I verified the handling, that wasnt it.

Correct me if I am wrong on the other issue:

If you havent passed the start page, PastBack is True. Otherwise, it is false.

Is there a way to detect if a button has been clicked?
 
You have to write an onclick event handler for every button you have. In design mode, just right click on the buton and choose properties, events, onclick. Be sure your button is an web control.
 
If you click the btnCancel, then it tries to reload the page, gets a post back and goes to the login page. If you manually push it to the end of the end if, it will go through the btnCancel subroutine

Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
        I have my code here
        Else
            Dim url As String
            url = "LogIn.aspx"
                Response.Redirect(url)
        End If
    End Sub

     Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        go back with the id you came in with
        Dim url As String
        url = "Main.aspx?id=" & Request("ID")
        Response.Redirect(url)

    End Sub
 
Try with this:

<asp:button id=Cancel runat="server" Text="Cancel" ></asp:button>

___________________________________________________

/* Sorry, but I am not familiar with VB */

if (IsPostBack)
{
&nbsp&nbspbool clicked = false;
&nbsp&nbspstring BtnValue = Request.QueryString["Cancel"];
&nbsp&nbspif (BtnValue != null)
&nbsp&nbsp{
&nbsp&nbsp&nbsp&nbspif (BtnValue == "Cancel")
&nbsp&nbsp&nbsp&nbsp&nbsp&nbspclicked = true;
&nbsp&nbsp}

&nbsp&nbspif (clicked == false) /* not clicked */
&nbsp&nbsp&nbsp&nbspResponse.Redirect("Login.aspx");
}

___________________________________________________
 
Back
Top