IsPostBack always returns false

Each time I test IsPostBack in PageLoad (), it returns false if post data is present. My first reaction was to check if the runat = "server" tag was on the form or submit button. However, they were all added, and the WriteEmail.aspx page still always returns false for IsPostBack. I also tried using IsCrossPagePostBack instead of IsPostBack.

ListInstructors.aspx:

<form runat="server" method="post" action="WriteEmail.aspx"> ... <input type="submit" id="writeEmail" value="Write Email" runat="server" /> </form> 

WriteEmail.aspx:

 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Response.Redirect("ListInstructors.aspx"); } } 
+4
source share
2 answers

Post! = Postback. Sending occurs when you send back to the same page. The action in your form is sent to a new page.

It seems that all you do is use the WriteEmail.aspx page to send a message and then return to where you just were. You don’t even show the form to receive the text there. This is a very ... Classic ASP-ish ... way to handle things.

Instead, put the code that you use to send the message to the class class, and if necessary, put the class in the App_Code folder. Also change the submit button to <asp:button ... /> Then you can just call it code from the server. Click an event for your button and never leave the ListInstructors.aspx page.


In response to your comment: None. MSDN :

... enter a crosstab request by assigning the page URL to the PostBackUrl property of the button control that implements the IButtonControl interface.

+13
source

IsPostBack not true because the form is not submitted from the WriteEmail.aspx page; then submit the form from the same page as PostBack calls. If you submitted the form from the WriteEmail.aspx page, it will be PostBack ; as is, it's just a message.

You can find this link on MSDN:

http://msdn.microsoft.com/en-us/library/ms178141.aspx

+2
source

All Articles