Custom Control with TextBox in GridView in ASP.net - asp.net

I have created a Custom Control with textbox.
I am calling it in GridView. When an Update event is fired it always saves 0.
I have used following code , could any one help in the same.
Following is the code used for custom control.
ASCX Code
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ItemRequiredTextBox.ascx.cs"
Inherits="ItemRequiredTextBox" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:TextBox ID="txtWin_Delievered_Qty" runat="server" >
<asp:FilteredTextBoxExtender ID="ftbe3" runat="server" TargetControlID="txtWin_Delievered_Qty"
ValidChars="1234567890" />
<asp:CompareValidator ID="CompareValidator1" runat="server" Display="None" ValueToCompare='<%# this.Text2 %>' ControlToValidate="txtWin_Delievered_Qty" Type="Integer"
ErrorMessage="Quantity to be delievered can not be More than Required Quantity"
Operator="LessThanEqual">
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" TargetControlID="CompareValidator1"
runat="server">
<asp:CompareValidator ID="CompareValidator2" runat="server" Display="None" ValueToCompare='<%# this.Text1 %>' ControlToValidate="txtWin_Delievered_Qty" Type="Integer"
ErrorMessage="Quantity delievered can not be less than delievered Quantity" Operator="GreaterThanEqual">
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" TargetControlID="CompareValidator2"
runat="server">
ASCX.CS Code
using System;
using System.Data;
using System.ComponentModel;
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;
public partial class ItemRequiredTextBox : System.Web.UI.UserControl
{
[Bindable(true, BindingDirection.TwoWay)]
protected void Page_Load(object sender, EventArgs e)
{
}
private int TexT1;
private int TexT2;
public int Text1
{
get { return TexT1; }
set { TexT1 = value; }
}
public int Text2
{
get { return TexT2; }
set { TexT2 = value; }
}
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
}

Create a public property in the usercontrol to get textbox value:
public string Text
{
get
{
return txtWin_Delievered_Qty.Text;
}
}
And access the value in the gridview update event:
ItemRequiredTextBox irtBox = (ItemRequiredTextBox)gvMyGridView.Rows[e.Item.ItemIndex].FindControl("updatedBy");
string myText = irtBox.Text;
Here gvMyGridView is your gridview

Related

asp.net webform can't find usercontrol

I don't know how to get usercontrol's function GetValue(), I always get Error code CS1061.
First I can't get usercontrol ID testControl.
I have found lots example, but almost example can use like my code.
I don't know what's wrong about it.
This is all my code.
User Control Part
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="testControl.ascx.cs" Inherits="MyWeb.UserControl.testControl" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<style type="text/css">
.center {
text-align: center;
}
</style>
<asp:UpdatePanel ID="upUserControl" runat="server">
<ContentTemplate>
<table>
<thead>
<tr>
<td colspan="4">
<div class="center">
<asp:Label ID="lblTitle" runat="server" Text="查詢"></asp:Label>
</div>
</td>
</tr>
</thead>
<tbody>
<tr>
<td><asp:Label ID="lblName" runat="server" Text="姓名"></asp:Label></td>
<td><asp:TextBox ID="txtName" MaxLength="10" runat="server"></asp:TextBox></td>
<td><asp:Label ID="lblIdentify" runat="server" Text="身分證字號/統編:"></asp:Label></td>
<td><asp:TextBox ID="txtIdentify" MaxLength="10" runat="server"></asp:TextBox></td>
<td><asp:Button ID="btnQuery" runat="server" Text="查詢" OnClick="btnQuery_Click"/></td>
</tr>
</tbody>
</table>
</ContentTemplate>
</asp:UpdatePanel>
Code Behind of User Control
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyWeb.UserControl
{
public partial class testControl : System.Web.UI.UserControl
{
public string Name, Identify;
public string GetValue()
{
return txtName.Text + txtIdentify.Text;
}
protected void Page_Load(object sender, EventArgs e)
{ }
protected void btnQuery_Click(object sender, EventArgs e)
{ }
}
}
asp Page
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="testDynamicSelect.aspx.cs" Inherits="MyWeb.testDynamicSelect" %>
<%# Register Src="~/UserControl/testControl.ascx" TagPrefix="ucTest" TagName="ctrl" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<ucTest:ctrl runat="server" ID="testControl" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</asp:Content>
Code Behind of asp Page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyWeb
{
public partial class testDynamicSelect : Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
//I can't get testControl
Response.Write(testControl.GetValue());
}
}
}
I try to reference namespace MyWeb.UserControl, and it can work now.
In my company old project, it wouldn't reference just like my question.
But in my new project can't work. It have to reference namespace MyWeb.UserControl.
Who can tell me how it work?
using MyWeb.UserControl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyWeb
{
public partial class testDynamicSelect : Page
{
testControl ucl = new testControl();
//UserControl ucl = new UserControl;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Console.WriteLine(cul.GetValue());
//Button1
}
}
}

How to Add One event to each Item On A CheckboxList Asp.net

How Can I Add One Event to Each item On A CheckBoxList, pr example I Wanto to add One Click Event to check What Item Has been checked.
thanks in advance.
Each item in CheckBoxList is of type System.Web.UI.WebControls.ListItem and has no events defined.
That's a bit tricky with the CheckBoxList. Don't think there's a straight way to add an click-event to each item, since the ListItem-class doesn't have any events.
You could set AutoPostBack="true" on the CheckBoxList and check on page load which items are selected, but you wouldn't know easy which was the last one clicked.
Other solution is to get rid of the CheckBoxList and create just CheckBoxes and set the click-event on those to the same event-method. And there you could check the sender.
ASPX:
<asp:CheckBox ID="CheckBox1" Text="A" OnCheckedChanged="CheckBox_Clicked" AutoPostBack="true" runat="server" />
<asp:CheckBox ID="CheckBox2" Text="B" OnCheckedChanged="CheckBox_Clicked" AutoPostBack="true" runat="server" />
<asp:CheckBox ID="CheckBox3" Text="C" OnCheckedChanged="CheckBox_Clicked" AutoPostBack="true" runat="server" />
Code behind:
void CheckBox_CheckedChanged(object sender, EventArgs e)
{
Console.WriteLine(((CheckBox)sender).Text);
}
Or you could make your own custom CheckBoxList that handles click-events on items.
OK. So I found this question/answer and it didn't help me out. While the provided answer is correct, there is an easy way to build a CheckBoxList-like control witha Repeater control.
Turns out that you can use a Repeater with an ItemTemplate with a CheckBox.
I have a complete explanation here: http://www.rhyous.com/2014/10/17/aspx-checkboxlist-alternative-that-allows-for-the-oncheckedchanged-event/
I also copied the needed data here in this answer:
Default.aspx
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CheckBoxListExample._Default" %>
<%# Import Namespace="CheckBoxListExample" %>
<%# Import Namespace="CheckBoxListExample.Models" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:CheckBox ID="cb1" runat="server" AutoPostBack="true" OnCheckedChanged="RepeaterCheckBoxChanged"
Text="<%# ((CheckBoxViewModel)Container.DataItem).Name %>"
Checked="<%# ((CheckBoxViewModel)Container.DataItem).IsChecked %>" />
</ItemTemplate>
</asp:Repeater>
</div>
</asp:Content>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using CheckBoxListExample.Models;
namespace CheckBoxListExample
{
public partial class _Default : Page
{
private List<CheckBoxViewModel> _ViewModels;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var _ViewModels = new List<CheckBoxViewModel>
{
new CheckBoxViewModel {Name = "Test1", IsChecked = true},
new CheckBoxViewModel {Name = "Test2"},
new CheckBoxViewModel {Name = "Test3"}
};
Repeater1.DataSource = _ViewModels;
Repeater1.DataBind();
}
}
protected void RepeaterCheckBoxChanged(object sender, EventArgs e)
{
var cb = sender as CheckBox;
if (cb == null) return;
if (cb.Checked)
{
// Insert
}
else
{
// Delete
}
}
}
}
CheckBoxViewModel
namespace CheckBoxListExample.Models
{
public class CheckBoxViewModel
{
public string Name { get; set; }
public bool IsChecked { get; set; }
}
}

update the textbox text property through loop

I want to update the text property of my textbox control in Asp.Net from within loop.I have tried using Ajax updatepanel with the timer control but unable to update the text property.I have been searching this since last week but unable to find any answer any help would be higly appreciated
Following is the detail:
This is my button click event in this code you can see I am updating the
TxtContent.Text
within a loop the text is being returned by a user defined function called
ReturnBodyText()
afterwards I am assigning the text to the viewstate so that at the timer tick event I can recall the text and update the textbox text property and then at the timer tick event assigning the viewstate values to the textbox.
protected void Button4_Click(object sender, EventArgs e)
{
ArrayList FilePath = (ArrayList)ViewState["ArrayList"];
int i = 0;
int b = 1;
foreach(string[] sr in FilePath)
{
string Month = sr[i];
string datewithzero;
datewithzero = String.Format("{0:00}", b);
string[] FilesArray = (string[])listfiles(Month, datewithzero).ToArray(typeof(string));
foreach (string FileNameWithExtension in FilesArray)
{
ListBox4.Items.Add(FileNameWithExtension);
TxtContent.Text = ReturnBodyText(Month, datewithzero, FileNameWithExtension);
ViewState["Content"] = TxtContent.Text;
Timer1.Enabled = true;
Timer1_Tick(ViewState["Content"], e);
}
i = i + 1;
b = b + 1;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
TxtContent.Text =(string) ViewState["Content"];
TxtContent.DataBind();
}
I Hope the above description will help you guys in understanding my problem
The complete aspx file and the code behind is as follows:
Aspx Code:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:ListBox ID="ListBox1" runat="server" Height="509px" Width="59px">
</asp:ListBox>
<asp:Button ID="Button2" runat="server" Height="26px" onclick="Button2_Click"
Text="To be pressed first" Width="130px" />
<asp:Button ID="Button3" runat="server" onclick="Button3_Click"
Text="To be pressed 2nd" Width="131px" Height="26px" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="1000"
ontick="Timer1_Tick" Enabled="False">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="TxtContent" runat="server" Height="508px" AutoPostBack="True"
TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button5" runat="server" Height="26px" onclick="Button4_Click"
Text="To be pressed Third" Width="122px" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
- Codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Collections;
public partial class _Default : ftp
{
protected void Button2_Click(object sender, EventArgs e)
{
string[] array = (string[])listfiles().ToArray(typeof(string));
ViewState["FolderName"] = array;
foreach (string FileName in array)
{
ListBox1.Items.Add(FileName);
}
}
protected void Button3_Click(object sender, EventArgs e)
{
string[] arraylistbox2 = (string[])ViewState["FolderName"];
string[] arrays = new string[12];
ArrayList ListPath = new ArrayList();
int dateFolder;
foreach (string FileName in arraylistbox2)
{
dateFolder = Convert.ToInt16(FileName);
dateFolder = dateFolder - 1;
ListPath.Add((string[])(listfiles(FileName).ToArray(typeof(string))));
}
ViewState["ArrayList"] = ListPath;
}
protected void Button4_Click(object sender, EventArgs e)
{
ArrayList FilePath = (ArrayList)ViewState["ArrayList"];
int i = 0;
int b = 1;
foreach(string[] sr in FilePath)
{
string Month = sr[i];
string datewithzero;
datewithzero = String.Format("{0:00}", b);
string[] FilesArray = (string[])listfiles(Month, datewithzero).ToArray(typeof(string));
foreach (string FileNameWithExtension in FilesArray)
{
TxtContent.Text = ReturnBodyText(Month, datewithzero, FileNameWithExtension);
ViewState["Content"] = TxtContent.Text;
Timer1.Enabled = true;
Timer1_Tick(ViewState["Content"], e);
}
i = i + 1;
b = b + 1;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
TxtContent.Text =(string) ViewState["Content"];
TxtContent.DataBind();
}
Sadly, your code did not help me much. However, I wrote this which I believe does what you want -partially-. It seems to me nothing more can be done though. Here is the code:
.aspx file:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer runat="server" ID="Timer1" Interval="1000" Enabled="true"
ontick="Timer1_Tick" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
aspx.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected static string keeper;
protected static bool inUse = false;
protected void Page_Load(object sender, EventArgs e) {}
protected void Button1_Click(object sender, EventArgs e)
{
Thread worker = new Thread(new ThreadStart(workerFunction));
worker.Start();
return;
}
protected void workerFunction()
{
inUse = true;
for (int i = 0; i < 3; i++)
{
TextBox1.Text += "foo";
keeper = TextBox1.Text;
Thread.Sleep(1000);
}
inUse = false;
keeper = "";
}
protected void Timer1_Tick(object sender, EventArgs e)
{
if (inUse)
{
TextBox1.Text = Convert.ToString(keeper);
}
}
}
}

Append empty text box Rows to a grid

I have a grid with two columns first column with check box and second column with text box. I have a add and save button down the grid.Can you please tell how to obtain if i click add button i need to append one more row to the grid with empty text box and check box so that i can type and click save
need to do possibly without java script
If I am getting you correctly you want something like below
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grdDemo" runat="server" AutoGenerateColumns="False" EnableModelValidation="True">
<Columns>
<asp:TemplateField HeaderText="CheckBox">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("IsCheckBox") %>' Enabled="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TextBox">
<ItemTemplate>
<asp:TextBox ID="Label1" runat="server" Text='<%# Bind("IsTextBox") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Save" />
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
grdDemo.DataSource = new Demo().GetData();
grdDemo.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
var list = new Demo().GetData();
list.Add(new Demo() {IsCheckBox = false, IsTextBox = ""});
Cache["list"] = list;
grdDemo.DataSource = list;
grdDemo.DataBind();
}
}
public class Demo
{
public bool IsCheckBox { get; set; }
public string IsTextBox { get; set; }
public List<Demo> GetData()
{
if (HttpContext.Current.Cache["list"] == null)
{
List<Demo> list = new List<Demo>()
{
new Demo(){IsCheckBox=true,IsTextBox = "text1"},
new Demo(){IsCheckBox=false,IsTextBox = "text2"},
};
return list;
}
return (List<Demo>)HttpContext.Current.Cache["list"];
}
}

CustomValidator problems within ASP.NET

EDIT
Fixed the problem - I needed to add the validators to a ValidationGroup and then call each of the validation controls Validate() method on the submit behaviour of the button.
protected void btnDone_Click(object sender, EventArgs e)
{
this.cvValidation.Validate();
this.revYear.Validate();
if (Page.IsValid)
{
DateTime sub = Convert.ToDateTime(String.Format("01/{0}/{1}", ddlMonth.SelectedValue, txtYear.Text));
string str = sub.ToString("MMMM") + " " + sub.ToString("yyyy");
pcePopUp.Commit(str);
}
}
I am trying to add a CustomValidator to my UserControl but I cannot get the validator to run as it should. What I am trying to achieve is to test to see if the month/year is in the future.
After breaking into the code I have noticed that the validateDate method is being fired twice. Any help on this situation would be greatly appreciated.
Could it be a problem with the way I am retrieving data from the controls as using the following two methods.
private void loadPostBackData()
{
loadPostBackDataItem(((TextBox)puymcStartDate.FindControl("txtDate")));
loadPostBackDataItem(((TextBox)puymcEndDate.FindControl("txtDate")));
}
private void loadPostBackDataItem(TextBox control)
{
string controlId = control.ClientID.Replace("_", "$");
string postedValue = Request.Params[controlId];
if (!String.IsNullOrEmpty(postedValue))
{
control.Text = postedValue;
}
else
{
control.Text = String.Empty;
}
}
UserControl code
ASP.NET Code
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="CtrlPopUpYearMonthCalendar.ascx.cs" Inherits="CLIck10.Controls.CtrlPopUpYearMonthCalendar" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:TextBox ID="txtDate" ReadOnly="true" runat="server" />
<div id="divPopUp" runat="server" class="box" style="width:320px;visibility:hidden;margin-left:5px;">
<div class="boxTitle">
<h1>Choose date</h1>
</div>
<div style="padding:5px;">
<asp:UpdatePanel id="upPopUp" UpdateMode="Always" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlMonth" runat="server" /> <asp:TextBox ID="txtYear" runat="server" />
<asp:Button ID="btnDone" Text="Done" runat="server" UseSubmitBehavior="false" onclick="btnDone_Click" />
<asp:RegularExpressionValidator ID="revYear" ValidationExpression="^[0-9]{4}$" ControlToValidate="txtYear" Display="Dynamic" Text="(*)" ErrorMessage="Year must be valid" runat="server" />
<asp:CustomValidator ID="cvValidation" Text="(*)" Display="Dynamic" ErrorMessage="Date must be in the future" OnServerValidate="validateDate" ValidateEmptyText="true" runat="server" />
<asp:ValidationSummary ID="vsDate" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
<ajaxToolkit:PopupControlExtender ID="pcePopUp" PopupControlID="divPopUp" TargetControlID="txtDate" Position="Right" runat="server" />
Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.Diagnostics;
namespace CLIck10.Controls
{
public partial class CtrlPopUpYearMonthCalendar : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DateTime month = Convert.ToDateTime("01/01/2000");
for (int i = 0; i < 12; i++)
{
DateTime nextMonth = month.AddMonths(i);
ListItem item = new ListItem();
item.Text = nextMonth.ToString("MMMM");
item.Value = nextMonth.Month.ToString();
ddlMonth.Items.Add(item);
}
if (txtDate.Text.Equals(String.Empty))
{
ddlMonth.Items.FindByValue(DateTime.Now.AddMonths(1).Month.ToString()).Selected = true;
if (DateTime.Now.Month.ToString("MM").Equals("12"))
{
txtYear.Text = DateTime.Now.AddYears(1).ToString("yyyy");
}
else
{
txtYear.Text = DateTime.Now.ToString("yyyy");
}
}
else
{
DateTime date = Convert.ToDateTime("01, " + txtDate.Text);
ddlMonth.Items.FindByValue(date.Month.ToString()).Selected = true;
txtYear.Text = date.ToString("yyyy");
}
}
}
protected void btnDone_Click(object sender, EventArgs e)
{
DateTime sub = Convert.ToDateTime(String.Format("01/{0}/{1}", ddlMonth.SelectedValue, txtYear.Text));
string str = sub.ToString("MMMM") + " " + sub.ToString("yyyy");
pcePopUp.Commit(str);
}
public void validateDate(object sender, ServerValidateEventArgs e)
{
DateTime sub = Convert.ToDateTime(String.Format("01/{0}/{1}", ddlMonth.SelectedValue, txtYear.Text));
if (sub >= DateTime.Now)
{
e.IsValid = true;
}
else
{
e.IsValid = false;
}
}
}
}
After experimenting with just embedding the control in a blank page It works so it must be something to do with the page I am working on.
I tried out your code as a page (not a usercontrol) and it worked fine.
Are you dynamically adding your usercontrols to the page?

Resources