AjaxToolkit ModalPopup Extender - asp.net

I am using AjaxToolKit and have created a gridview with Details button. I want to open a panel that will have 2 more gridviews upon Details button click as ModalPopupExtender. It should also highlight the row which is being edited.
I am getting this error...
Webpage error details
Message: Invalid character
Line: 269
Char: 7
Code: 0
URI: http://localhost:5427/ModalPopUpInGridView/Default3.aspx
I checked both the design/source as well as the code but I couldn't find any invalid characters. Also when I click on the Details buttons at runtime the gridview disappears.
Any suggestions?
Here is the complete source code:
HTML Part:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit"%>
<!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>Untitled Page</title>
<style>
.modalBackground
{
background-color:Gray;
filter:alpha(opacity=70);
opacity:0.7;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="scriptManager" runat="server" />
<div>
<p style="background-color:AliceBlue; width:95%">
Example of using a
ModalPopupExtender to edit the indivdual rows of a GridView.<br />
To test out the functionality,
click the Details button of any of the rows and watch what happens.<br />
</p>
<br />
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTitle" runat="server" Text="Customers" BackColor="lightblue" Width="95%" />
<asp:GridView
ID="gvCustomers" runat="server"
AutoGenerateColumns="false"
AllowPaging="true" AllowSorting="true"
PageSize=10 OnPageIndexChanging="myGridView_PageIndexChanging"
OnRowDataBound="Gridview_RowDataBound" EnableViewState="false"
Width="95%">
<AlternatingRowStyle BackColor="AliceBlue"
/>
<HeaderStyle HorizontalAlign="Left"
/>
<Columns>
<asp:TemplateField HeaderText="V">
<ItemTemplate>
<asp:CheckBox ID="chkVerified" runat="server"
Checked='<%# Eval("V") == "True" ? true : false %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NT">
<ItemTemplate>
<asp:CheckBox ID="chkDeleted" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="P">
<ItemTemplate >
<asp:Label ID="P" runat="server" Text='<%# Eval("P") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FN">
<ItemTemplate >
<asp:Label ID="FN" runat="server" Text='<%# Eval("FN") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MN" >
<ItemTemplate >
<asp:Label ID="MN" runat="server" Text='<%# Eval("MN") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LN" >
<ItemTemplate >
<asp:Label ID="LN" runat="server" Text='<%# Eval("LN") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<ItemTemplate >
<asp:Label ID="Title" runat="server" Text='<%# Eval("Title") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnViewDetails"
runat="server"
Text="Details"
OnClick="btnViewDetails_Click"
/>
</ItemTemplate>
<ControlStyle Width="50px" />
<HeaderStyle Width="60px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button id="btnShowPopup" runat="server" style="display:none" />
<ajaxToolKit:ModalPopupExtender
ID="mdlPopup" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlPopup"
CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlPopup" runat="server" Width="500px" style="display:none">
<asp:UpdatePanel ID="updPnlCustomerDetail" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblCustomerDetail" runat="server"
Text="Customer
Detail" BackColor="lightblue" Width="95%" />
<asp:Panel ID="pnlPopupInner" runat="server">
<table>
<tr><td>Test1</td></tr>
<tr><td>Test2</td></tr>
<tr><td>Test3</td></tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<div align="right" style="width:95%">
<asp:Button
ID="btnSave" runat="server"
Text="Save"
OnClientClick="alert(’Sorry, but I didnt implement save because I
dont want my northwind database getting messed up.’); return false;"
Width="50px" />
<asp:Button ID="btnClose" runat="server" Text="Close" Width="50px" />
</div>
</asp:Panel>
</div>
</form>
</body>
</html>
Code Behind:
using System;
using System.Drawing;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MDRTeachersTest; //Webservice
public partial class Default3 : System.Web.UI.Page
{
string sFullName = "";
int firstRow = 0;
private int selectedIndex;
protected void Page_Load(object sender, EventArgs e)
{
sFullName = "";
firstRow = -1;
if (!IsPostBack)
{
bool bTest = loginToWS();
if (bTest == true)
{
gvCustomers.Visible = true;
}
}
}
private bool loginToWS()
{
//code to login to web service and fetch the object filled with data.
}
private static DataTable dtInfoPersonnel(Organization org)
{
string RowId = "";
string PersonId = "";
bool firsttime = true;
DataRow dr;
DataTable dtTemp = new DataTable();
dtTemp.Columns.Add("V", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("NT", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("P");
dtTemp.Columns.Add("FN");
dtTemp.Columns.Add("MN");
dtTemp.Columns.Add("LN");
dtTemp.Columns.Add("Title");
dtTemp.Columns.Add("Remove");
dtTemp.Columns.Add("Vacant", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("Status");
dtTemp.Columns.Add("RowId");
dtTemp.Columns.Add("PersonId");
dtTemp.Columns.Add("Verified", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("Substitute", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("ComputerUser", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("YearsExperience");
dtTemp.Columns.Add("Closed", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("AP", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("CU", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("PF", System.Boolean.FalseString.GetType());
dtTemp.Columns.Add("historicAlphaCode");
foreach (K12Personnel person in org.persons)
{
//Code to fill DATATABLE with the data.
}
return dtTemp;
}
protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(gvCustomers, "Select$" + e.Row.RowIndex.ToString()));
//We're only interested in Rows that contain data
//get a reference to the data used to databound the row
DataRowView drv = ((DataRowView)e.Row.DataItem);
if (sFullName == drv["FN"].ToString() + drv["LN"].ToString())
{
//If it's the same category as the previous one
//Increment the rowspan
for (int cellCount = 0; cellCount < 6; cellCount++)
{
if (gvCustomers.Rows[firstRow].Cells[cellCount].RowSpan == 0)
gvCustomers.Rows[firstRow].Cells[cellCount].RowSpan = 2;
else
gvCustomers.Rows[firstRow].Cells[cellCount].RowSpan += 1;
//Remove the cell
e.Row.Cells.RemoveAt(0);
}
}
else //It's a new category
{ //Set the vertical alignment to top
e.Row.VerticalAlign = VerticalAlign.Top;
//Maintain the category in memory
sFullName = drv["FN"].ToString() + drv["LN"].ToString();
firstRow = e.Row.RowIndex;
}
}
}
catch (Exception ex)
{
}
}
protected void myGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DataTable dtTemp1 = new DataTable();
dtTemp1 = (DataTable)Session["PersonnelInfo"];
dtTemp1.DefaultView.Sort = "LN " + "ASC";
gvCustomers.DataSource = dtTemp1;
gvCustomers.PageIndex = e.NewPageIndex;
gvCustomers.DataBind();
}
protected void btnViewDetails_Click(object sender, EventArgs e)
{
this.updPnlCustomerDetail.Update();
this.mdlPopup.Show();
}
When I run the code. It does display me the gridview but I see a error "Invalid Character" at the bottom left corner of the browser. The paging works but when I click on Details button the whole gridview disappears.

It might be because of this line:
OnClientClick="alert(’Sorry, but I didnt implement save because I dont want my northwind database getting messed up.’); return false;"
You need to use ' instead of ’
This jsfiddle confirms my suspicion.

Related

How to hard-code a GridView in my .aspx file?

I want to have a GridView with static data in it, not linked to any database or data source, and I would like to hard-code it directly in my aspx file.
I'm brand new to ASP.NET and have no idea what I'm doing, and for whatever reason I can't find anything online about how to do this.
I'm trying to create a one-column table with a heading of "Hello World" and two data items, "Hello" and World". Here is what I'm trying, but nothing is showing up on the page when I run it:
<asp:GridView ID="GridView" runat="server">
<Columns>
<asp:TemplateField HeaderText ="Hello World">
<ItemTemplate>
<asp:Label ID="lblHello" runat ="server" Text ="Hello"/>
</ItemTemplate>
<ItemTemplate>
<asp:Label ID="lblWorld" runat ="server" Text ="World"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You want to assign either IEnumerable, DataSet or DataTable to display data in GridView.
<asp:GridView ID="GridView" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Hello World">
<ItemTemplate>
<asp:Label ID="lblHello" runat="server"
Text='<%# Eval("Text1") %>' />
<asp:Label ID="lblWorld" runat="server"
Text='<%# Eval("Text2") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
public class Item
{
public string Text1 { get; set; }
public string Text2 { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
GridView.DataSource = new List<Item>
{
new Item {Text1 = "Hello", Text2 = "World"}
};
GridView.DataBind();
}
Updated:
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
GridView.DataSource =
new Dictionary<string, string> { { "Hello", "World" } };
GridView.DataBind();
}
</script>
<asp:GridView ID="GridView" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Hello World">
<ItemTemplate>
<asp:Label ID="lblHello" runat="server"
Text='<%# Eval("Key") %>' />
<asp:Label ID="lblWorld" runat="server"
Text='<%# Eval("Value") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Can not get textbox value inside datalist

I am trying to get the value of textbox "Qty" inside a datalist. It does not work. What is wrong? I have both the CartItem label and the datelist inside the ajax updatepanel. Thanks for any help. Here is my code:
<asp:Label ID="CartItems" runat="server" Text="CartItem"></asp:Label>
<br />
<asp:DataList ID="DataList1" runat="server" CellPadding="10"
DataKeyField="product_id" DataSourceID="SqlDataSource1" RepeatColumns="2">
<ItemTemplate>
<asp:Label ID="product_id" runat="server"
Text='<%# Eval("product_id") %>' /><br/>
<asp:Label ID="product_name" runat="server"
Text='<%# Eval("product_name") %>' />
<br />
Qty
<br/>
<asp:TextBox ID="Qty" runat="server"></asp:TextBox>
<asp:Button ID="ButtonAddToCart" runat="server" Text="Add to Cart"
onClick="ButtonAddToCart_Click"/>
<br />
</ItemTemplate>
</asp:DataList>
and here is the button click event. The CartItem has null value:
protected void ButtonAddToCart_Click(object sender, EventArgs e)
{
CartItem.Text = DataList1.FindControl("Qty").ToString();
}
TextBox Qty = (TextBox)DataList1.FindControl("Qty");
if(Qty != null)
{
CartItem.Text =Qty.Text;
}
You can use NamingContainer or Parent to access sibling controls
protected void ButtonAddToCart_Click(object sender, EventArgs e)
{
var button = sender as Button;
var textbox = button.NamingContainer.FindControl("Qty") as TextBox;
CartItem.Text = textbox.Text;
}
I prefer you to use item_command event of the datalist
do some think like this.
<asp:Label ID="CartItems" runat="server" Text="CartItem"></asp:Label>
<br />
<asp:DataList ID="DataList1" runat="server" CellPadding="10" DataKeyField="product_id" DataSourceID="SqlDataSource1" RepeatColumns="2">
<ItemTemplate>
<asp:Label ID="product_id" runat="server"
Text='<%# Eval("product_id") %>' /><br/>
<asp:Label ID="product_name" runat="server"
Text='<%# Eval("product_name") %>' />
<br />
Qty
<br/>
<asp:TextBox ID="Qty" runat="server"></asp:TextBox>
<asp:Button ID="ButtonAddToCart" runat="server" Text="Add to Cart" CommandName="addtocart2" OnCommand="DataList1_ItemCommand"
/>
<br />
</ItemTemplate>
</asp:DataList>
Here is the item_command event that works.
public void DataList1_ItemCommand(object source, System.Web.UI.WebControls.CommandEventArgs e){
TextBox qtytxtbox = DataList1.FindControl("Qty") as TextBox;
}
You can do like this
protected void ButtonAddToCart_Click(object sender, EventArgs e)
{
Button ButtonAddToCart= (Button)sender;
DataListItem item = (DataListItem)ButtonAddToCart.NamingContainer;
var textbox = (TextBox)item.FindControl("Qty");
}
try this one
TextBox txtquantity = (TextBox)(e.Item.FindControl("Qty"));
simply use this......You will get the value in txtquantity

How to create a custom control dynamically?

Let me get this straight. I manage to create a custom Gridview with a single checkbox but my problem here is that I want to include multiple dynamic Checkbox.
Here is my code:
<%# Control Language="C#" AutoEventWireup="true" EnableTheming="true" CodeFile="GridviewControl.ascx.cs" Inherits="UserControl_GridviewControl" %>
<link href="../Template/CSS/Style.css"type="text/css" rel="Stylesheet" />
<div>
<span id="Span5" style="font-family: Arial; font-size:12px;" ><asp:Label ID="lblCount" runat="server" Text="0" Font-Bold="true"></asp:Label>
Record/s</span>
<span class="maintenance-btns">
<asp:Button ID="btnNew" runat="server" Text=" New " onclick="btnNew_Click"/>
<asp:Button ID="btnDel" runat="server" Text=" Delete " onclick="btnDel_Click"/>
</span>
</div>
<asp:Panel ID="pnlPc" runat="server" CssClass="div-grid" ScrollBars="Auto">
<asp:GridView ID="gvListing" runat="server" AllowPaging="True" AutoGenerateSelectButton="true"
OnRowDataBound="gvListing_RowDataBound" skinid="gvListing"
onselectedindexchanged="gvListing_SelectedIndexChanged"
onpageindexchanging="gvListing_PageIndexChanging" PageSize="50" >
<FooterStyle CssClass="grid-footer" />
<Columns>
<asp:TemplateField HeaderText="CheckAll">
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" AutoPostBack="true"
OnCheckedChanged="chkSelectAll_CheckedChanged" CssClass="select-all"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true"
OnCheckedChanged="chkSelect_CheckedChanged" CssClass="listing-checkbox"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
In this gridview I only have a checkboxes at the first column. I want to put the dynamically generated checkboxes at the last column.
P.S.: How do I retrieve the id with those dynamically create checkboxes?
You can do like this
protected void gvData_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow objRow in gvData.Rows)
{
TableCell tcCheckCell = new TableCell();
var checkBox = new CheckBox();
checkBox.CheckedChanged += checkBox_CheckedChanged;
tcCheckCell.Controls.Add(checkBox);
objRow.Cells.AddAt(0, tcCheckCell);
}
}
void checkBox_CheckedChanged(object sender, EventArgs e)
{
//do something
}

How can I set checkboxlist items as checked by default

In my page i have a CheckBoxList control and i would like all the checkboxes to be checked by default. how can i do that? i have tried couple ways but it is not doing it. here is my code behind:
protected void chkAll_CheckedChanged(object sender, EventArgs e)
{
foreach(GridViewRow gr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gr.FindControl("chkItem");
cb.Checked = true;
if(((CheckBox)sender).Checked)
cb.Checked = true;
else
cb.Checked = false;
}
}
and here is my ASPX code:
<asp:TemplateField HeaderText="Check All">
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" AutoPostBack="True" OnCheckedChanged="chkAll_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkItem" runat="server" />
</ItemTemplate>
</asp:TemplateField>
Use the following ASPX:
<asp:GridView runat="server" ID="m_gridView" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Check All">
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" AutoPostBack="True" OnCheckedChanged="chkAll_CheckedChanged" Checked="True" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkItem" runat="server" Checked="True" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
It should have Check All and the individual check boxes checked by default.
In you code behind do the following:
protected void chkAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox l_cbAll = (CheckBox)m_gridView.HeaderRow.FindControl("chkAll");
foreach (GridViewRow l_row in m_gridView.Rows)
{
CheckBox l_cb = (CheckBox)l_row.FindControl("chkItem");
l_cb.Checked = l_cbAll.Checked;
}
}

asp.net page not posting back, while the button click event is still firing

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.
comment this and try
<%-- <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>--%>
The button events are not being propagated out of the Table object that they are contained in.
Register the OnClick events for the 2 buttons in the table creation.

Resources