Okay, so I have this page, which has one Ajax:AsyncFileUploader
also some other ajax stuff like ModelPopUpExtender
etc. The problem is the two buttons in the page, of Cancel
and Submit
, both of them firing up but none is posting back, while I made sure none of the fields in the page are blank.
I know the events are firing up, because I debugged the JavaScript in Firebug
(a single step into and continue process took more than 4 min, while I was just almost held the F10 key for stepping into, down!)
If anyone wants code, please tell me I'd post it, but buttons are just in normal code so nothing special, that's why I am not posting the code, but in case required I can post entire page's code (which is pretty long I'd tell you, not really though, but at least just for posting purpose in here, somewhat around 200 lines). Any help anyone?
Edit: As per comment I am posting the code
code: aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Detailed Reminder</title>
<link href="StyleSheets/Default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function FileUploaded(sender, args) {
var filename = args.get_fileName();
var contentType = args.get_contentType();
var text = "Size of " + filename + " is " + args.get_length() + " bytes";
if (contentType.length > 0) {
text += " and content type is '" + contentType + "'.";
}
$get('LabelStatusUpload').innerHTML = "File Uploaded Successfully";
}
function UploadStarted(sender, args) {
$get('LabelStatusUpload').innerHTML = "Upload Started";
}
function ErrorUploaded(sender, args) {
$get('LabelStatusUpload').innerHTML = "Some Error Occured";
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<ajax:ToolkitScriptManager ID="SM1" runat="server">
</ajax:ToolkitScriptManager>
<asp:Button ID="Temp1" runat="server" Text="clear" />
<div id="UpperContainer">
<asp:Panel ID="PanelOuter" runat="server">
<asp:Table ID="TableDetailedRemidner" runat="server">
<asp:TableRow ID="TableRowName" runat="server">
<asp:TableCell ID="TableCell1" runat="server">
<asp:Label ID="LabelName" runat="server" AssociatedControlID="txtName" Text="Name"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell2" runat="server">
<asp:TextBox ID="txtName" runat="server" ToolTip="Name of the user to send the mail to"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRowEmail" runat="server">
<asp:TableCell ID="TableCell3" runat="server">
<asp:Label ID="LabelEmail" runat="server" AssociatedControlID="txtEmail1" Text="Email 1"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell4" runat="server">
<asp:TextBox ID="txtEmail" runat="server" Width="560px"></asp:TextBox>
<asp:RegularExpressionValidator ID="regexEmailValidator" runat="server" ControlToValidate="txtEmail"
Display="Dynamic" Text="Invalid Email" ValidationExpression="\w+([-+.’]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRowSubject" runat="server">
<asp:TableCell ID="TableCell5" runat="server">
<asp:Label ID="LabelSubject" runat="server" AssociatedControlID="txtSubject" Text="Subject"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell6" runat="server">
<asp:TextBox ID="txtSubject" runat="server" AutoComplete="off" Width="560px"></asp:TextBox>
<asp:Panel ID="PanelDefaultSubjects" runat="server">
<div>
<asp:UpdatePanel ID="UpdatePanelSubject" runat="server">
<ContentTemplate>
<asp:RadioButtonList ID="RadioSubjectList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioSubjectList_SelectedIndexChanged">
<asp:ListItem Text="Submit the reports"></asp:ListItem>
<asp:ListItem Text="prepare the presentation"></asp:ListItem>
<asp:ListItem Text="Custom" Value=""></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Panel>
<ajax:PopupControlExtender ID="PCESubject" runat="server" TargetControlID="txtSubject"
PopupControlID="PanelDefaultSubjects" CommitProperty="value" Position="Right"
OffsetX="5" CommitScript="e.value" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRowMessage" runat="server">
<asp:TableCell ID="TableCell7" runat="server">
<asp:Label ID="LabelMessageBody" runat="server" AssociatedControlID="txtMessageBody"
Text="Message"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell8" runat="server">
<asp:TextBox ID="txtMessageBody" runat="server" Columns="40" Rows="10" Multiline="true"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRowFileUpload" runat="server">
<asp:TableCell ID="TableCell9" runat="server">
<asp:Label ID="LabelFileAttached" runat="server" AssociatedControlID="AsyncFileUpload1"
Text="Attach a file"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell10" runat="server">
<ajax:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnClientUploadComplete="FileUploaded"
OnClientUploadError="ErrorUploaded" OnClientUploadStarted="UploadStarted" OnUploadedComplete="File_Uploaded"
UploaderStyle="Modern" ThrobberID="LabelThobber" />
<asp:Label ID="LabelThobber" runat="server" Style="display: none"><img alt="" src="Images/uploading.gif" /></asp:Label><br />
<asp:Label ID="LabelStatusUpload" runat="server" Text=" "></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRowDueDate" runat="server">
<asp:TableCell ID="TableCell11" runat="server">
<asp:Label ID="LabelDueDate" runat="server" AssociatedControlID="txtDueDate" Text="Due Date"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell12" runat="server">
<asp:TextBox ID="txtDueDate" runat="server" Width="560px"></asp:TextBox>
<ajax:MaskedEditExtender runat="server" ID="MEEDueDate" TargetControlID="txtDueDate"
Mask="99/99/9999" AutoComplete="true" MaskType="Date">
</ajax:MaskedEditExtender>
<ajax:MaskedEditValidator ID="MEVDueDate" runat="server" ControlExtender="MEEDueDate"
ControlToValidate="txtDueDate" IsValidEmpty="False" EmptyValueMessage="Due Date is required"
InvalidValueMessage="Due Date is required" EmptyValueBlurredText="*" InvalidValueBlurredMessage="*"
MaximumValueBlurredMessage="*" MinimumValueBlurredText="*" Display="Dynamic" />
<ajax:CalendarExtender ID="CalDueDate" runat="server" TargetControlID="txtDueDate">
</ajax:CalendarExtender>
</asp:TableCell></asp:TableRow>
<asp:TableRow ID="TableRowFrequency" runat="server">
<asp:TableCell ID="TableCell17" runat="server">
<asp:Label ID="LabelFrequency" runat="server" AssociatedControlID="txtFrequency"
Text="Frequency"></asp:Label>
</asp:TableCell><asp:TableCell ID="TableCell18" runat="server">
<asp:TextBox ID="txtFrequency" runat="server"></asp:TextBox>
<asp:Panel ID="PanelFrequency" runat="server">
<div>
<asp:UpdatePanel ID="UpdatePanelFrequency" runat="server">
<ContentTemplate>
<asp:RadioButtonList ID="RadioButtonFrequency" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="RadioSubjectFrequency_SelectedIndexChanged">
<asp:ListItem Text="15 min"></asp:ListItem>
<asp:ListItem Text="6 hr"></asp:ListItem>
<asp:ListItem Text="24 hr"></asp:ListItem>>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Panel>
<ajax:PopupControlExtender ID="PCEFrequency" runat="server" TargetControlID="txtFrequency"
PopupControlID="PanelFrequency" CommitProperty="value" Position="Right" OffsetX="5"
CommitScript="e.value" />
</asp:TableCell></asp:TableRow>
<asp:TableFooterRow>
<asp:TableCell ID="TableCellSubmit" runat="server">
<asp:Button ID="BtnSubmit" runat="server" OnClick="Submit_Click" Text="Set Reminder Detailed" />
</asp:TableCell><asp:TableCell ID="TableCellCancel" runat="server">
<asp:Button ID="BtnCancel" runat="server" OnClick="Cancel_Click" Text="Cancel" />
</asp:TableCell></asp:TableFooterRow>
</asp:Table>
</asp:Panel>
</div>
</form>
</body>
</html>
Code : page_Behind.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
//static protected string savePath;
//static protected int curFileSize;
//static protected bool IsFileAttached;
protected void Page_Load(object sender, EventArgs e)
{
CalDueDate.StartDate = DateTime.Now.Date;
CalDueDate.EndDate = DateTime.Now.Date.AddYears(1);
MEVDueDate.MinimumValue = DateTime.Now.Date.ToShortDateString();
MEVDueDate.MaximumValue = DateTime.Now.Date.ToShortDateString();
}
protected void RadioSubjectList_SelectedIndexChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(RadioSubjectList.SelectedValue))
{
// Popup result is the selected task
PCESubject.Commit(RadioSubjectList.SelectedValue);
}
else
{
// Cancel the popup
PCESubject.Cancel();
}
// Reset the selected item
RadioSubjectList.ClearSelection();
}
protected void RadioSubjectFrequency_SelectedIndexChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(RadioButtonFrequency.SelectedValue))
{
PCEFrequency.Commit(RadioButtonFrequency.SelectedValue);
}
else
{
PCEFrequency.Cancel();
}
RadioButtonFrequency.ClearSelection();
}
protected void File_Uploaded(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if (AsyncFileUpload1.HasFile)
{
string savePath = MapPath("~/Uploads/") + Path.GetFileName(DateTime.Now.Month + DateTime.Now.Day + " "
+ DateTime.Now.Hour + DateTime.Now.Minute + " " + e.FileName);
AsyncFileUpload1.SaveAs(savePath);
}
}
protected void Submit_Click(object sender, EventArgs e)
{
// On Submit button doesn't even reaches here, debugged and breakpoint on any of following code is never reached
int lastID = BusinessLayer.DetermineLastDetailedID();
// Some other logic unimportant at this point
BusinessLayer.AddDReminder(sender, e);
}
protected void Cancel_Click(object sender, EventArgs e)
{
txtName.Text = "";
txtEmail1.Text = "";
txtEmail2.Text = "";
txtEmail3.Text = "";
txtSubject.Text = "";
txtMessageBody.Text = "";
txtDueDate.Text = "";
txtFrequency.Text = "";
}
}
I copied your code, experienced the problem, fixed it and now the postback is happening just fine. MEVDueDate is always saying "IsValid=false" and because of that the PostBack was not getting to Page_Load (that is the expected behavior of that validator).
You need to change:
MEVDueDate.MinimumValue = DateTime.Now.Date.ToShortDateString();
MEVDueDate.MaximumValue = DateTime.Now.Date.ToShortDateString();
with this:
MEVDueDate.MinimumValue = DateTime.Now.Date.ToString("MM/dd/yyyy");
MEVDueDate.MaximumValue = DateTime.Now.Date.ToString("MM/dd/yyyy");
Select today on the calendar for Due Date, click cancel button and you should have a full postback. Please see that you are saying that min and max allowed dates are both today, so today is the only valid date that will allow the post-back to fire.
The reason is that your calendar picker writes on the textbox "03/08/2012" but the ToShortDateString() retrieves a string with another date format. You end up comparing "03/08/2012" with "08/03/2012".
You need to make sure the date format you use to set MEVDueDate.MinimumValue is according to the format that calendarPicker (CalDueDate) puts in txtDueDate.