Reputation:
Every time I test the IsPostBack in PageLoad() false is returned whether or not post data is present. My first reaction was to check to see if the runat="server" tag was missing from the form or submit button. However, they were all added and the WriteEmail.aspx page still always returns false for IsPostBack. I have also tried using IsCrossPagePostBack in place 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");
}
}
Upvotes: 5
Views: 11021
Reputation: 415810
Post != Postback. A postback is when you post back to the same page. The action on your form is posting to a new page.
It looks like all you're doing is using the WriteEmail.aspx page to send a message and then going back to where you just were. You're not even displaying a form to collect the text there. It's a very... Classic ASP-ish... way to handle things.
Instead, put the code you use to send a message in a separate class and if needed put the class in the App_Code folder. Also change the submit button to an <asp:button ... />
Then you can just call it the code from the server's Click event for your button and never leave your ListInstructors.aspx
page.
In response to the comment: No. From the docs:
... make a cross-page request by assigning a page URL to the PostBackUrl property of a button control that implements the IButtonControl interface.
Upvotes: 14
Reputation: 39480
The IsPostBack
is not true because the form is not being submitted from the WriteEmail.aspx
page; submitting a form from the same page is what causes a PostBack
. If you submitted the form from the WriteEmail.aspx
page, it would be a PostBack
; as it is, it's just a Post.
You might find this MSDN reference to be useful:
http://msdn.microsoft.com/en-us/library/ms178141.aspx
Upvotes: 2