I am working on a project where I am creating a dynamic table.Now depending upon my condition I am adding link button to table cells,but the click event of my link button is not working.I am not getting why its not working,neither its showing any error.
Following is my code
public void makeCalendar()
{
tblcalendar.Rows.Clear();
//for current month
DateTime startingdate = StartDateOfMonth(DateTime.Now.AddMonths(monthclickedno));
DateTime enddate = EndDateOfMonth(DateTime.Now.AddMonths(monthclickedno));
string startingday = startingdate.DayOfWeek.ToString();
int startingdayno = Convert.ToInt32(startingdate.DayOfWeek);
string endday = enddate.DayOfWeek.ToString();//like saturday is 6,stating is from monday with 1 and ending is sunday with 7
int enddayno = Convert.ToInt32(enddate.DayOfWeek);
//for prevoius month
DateTime enddateprevious = (EndDateOfMonth(DateTime.Now.AddMonths(monthclickedno)));
//for next month
DateTime startingdatenext = StartDateOfMonth(DateTime.Now.AddMonths(1));
DateTime dtstart=startingdate.AddDays(-(startingdayno+1));
//sMonthName = "January";
//int iMonthNo = Convert.ToDateTime("01-" + sMonthName + "-2011").Month;
for (int i = 0; i <7;i++)
{
TableRow tr = new TableRow();
for (int j = 0; j < 7;j++ )
{
TableCell tc = new TableCell();
clickablecell ctCell = new clickablecell();
//tc.ID = idtc.ToString();
idtc++;
if(i==0)
{
tr.CssClass = "firstrow";
tc.CssClass = "firstrowcell";
if (j == 0)
tc.Text = "Sun";
else if (j == 1)
tc.Text = "Mon";
else if (j == 2)
tc.Text = "Tue";
else if (j == 3)
tc.Text = "Wed";
else if (j == 4)
tc.Text = "Thu";
else if (j == 5)
tc.Text = "Fri";
else if (j == 6)
tc.Text = "Sat";
tr.Cells.Add(tc);
}
else{
tc.CssClass = "othercells";
dtstart=dtstart.AddDays(1);
//if date is single digit like 1,2
if (dtstart.ToString("dd").Substring(0, (dtstart.ToString("dd").Length)-1) == "0")
ctCell.Text = (dtstart.ToString("dd").Substring(1));
else
ctCell.Text = (dtstart.ToString("dd"));
ctCell.Attributes.Add("onmouseover", "defColor=this.style.backgroundColor; this.style.backgroundColor='LightGray';");
ctCell.Attributes.Add("onmouseout", "this.style.backgroundColor=defColor;");
//ctCell.ID = k.ToString();
k++;
ctCell.Click += new clickablecell.ClickEventHandler(textcell_Click);
//check for events in this date
DataTable dtevents = checkEvents(dtstart.ToString("dd-MM-yyyy"));
if (dtevents.Rows.Count != 0)
{
LinkButton lnkevent = new LinkButton();
//lnkevent.ClientIDMode ="Static";
lnkevent.ID = (i+j).ToString();
if (dtevents.Rows.Count == 1)
{
if (dtevents.Rows[0]["eventtype"].ToString() == "Holiday")
{
lnkevent.Text = dtevents.Rows[0]["eventtype"].ToString();
lnkevent.CssClass = "tcholidaytext";
ctCell.CssClass = "tcholidaytext";
}
else if (dtevents.Rows[0]["eventtype"].ToString() == "Event")
{
lnkevent.Text = dtevents.Rows[0]["eventtype"].ToString();
lnkevent.CssClass = "tceventtext";
ctCell.CssClass = "tceventtext";
}
else
{
lnkevent.Text = dtevents.Rows[0]["eventtype"].ToString();
lnkevent.CssClass = "tcimpdaytext";
ctCell.CssClass = "tcimpdaytext";
}
}
else
{
ctCell.CssClass = "tcmixtext";
}
//lnkevent.Attributes.Add("onClick", "test();");
//lnkevent.Click += lnkevent_OnClick;
lnkevent.Click += new EventHandler(lnkevent_OnClick);
ctCell.Controls.Add(lnkevent);
}
tr.Cells.Add(ctCell);
}
tblcalendar.Rows.Add(tr);
}
}
}
public void lnkevent_OnClick(object sender,EventArgs e)
{
lblmonthname.Text = "hellooo";
txttitle.Text = "";
}
Sounds like you are adding a button, but not binding an event listener to it. I don't know much about how asp.net does event binding, but it sounds like that could be your problem.
Maybe this link can help?
asp.net dynamically button with event handler
Related
I have dynamically created array CheckBoxes and I want to do a proper validation if none of them are selected inside the Panel but if I keep on using for loops, the MessageBox keeps on appearing.
Can anyone help me find a way to do this better? I just want to check if a checkbox control is checked inside the Panel and if not, display a messagebox that will say "Select a Checkbox!" only ONCE.
Here is the code that I made for the dynamically created checkboxes in a panel:
for (int z = 0; z <= dataGridView.Columns.Count - 1; z++)
{
chk[z] = new CheckBox();
chk[z].Name = dataGridView.Columns[z].Name;
chk[z].Text = dataGridView.Columns[z].Name;
chk[z].AutoCheck = true;
chk[z].Bounds = new Rectangle(10, 20 + padding + dynamicHeight, 40, 22);
chk[z].Location = new Point(0, dynamicHeight);
chk[z].Size = new Size(120, 21);
panelCol.BackColor = Color.White;
//MessageBox.Show(chk[z].Name + "" + dataGridView.Columns[z].Name);
panelCol.Controls.Add(chk[z]);
//panelCol.AutoScrollMinSize = new Size(0, 100);
dynamicHeight += 20;
panelCol.Size = new Size(120, dynamicHeight);
}
Here is the code that I have came up:
btnValidate.MouseClick += (s, e) => //btnValidate Event
{
for (int z = 0; z < dataGridView.Columns.Count - 1; z++ )
{
if(chk[z].Checked == true)
{
ValidateCheck(dataGridView, chk);
}
else if(chk[z].Checked == false)
{
MessageBox.Show("Select a CheckBox!");
}
}
};
ValidateCheck method:
public static void ValidateCheck(DataGridView dataGridView, CheckBox[] chk)
{
FileStream fs = new FileStream(#"C:\brandon\InvalidColumnCheck.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
StringBuilder sb = new StringBuilder();
decimal num;
sw.WriteLine("----------------------------");
sw.WriteLine("");
for (int j = 0; j < dataGridView.ColumnCount - 1; j++)
{
if (chk[j].Checked == true && chk[j].Name.Contains(dataGridView.Columns[j].Name))
{
string column = chk[j].Name;
for (int k = 0; k < dataGridView.RowCount; k++)
{
if (!Decimal.TryParse(dataGridView.Rows[k].Cells[column].Value.ToString(), out num))
{
if (dataGridView.Rows[k].Cells[dataGridView.Columns[column].Name].Value.ToString() == null || dataGridView.Rows[k].Cells[dataGridView.Columns[column].Name].Value.ToString() == "" || dataGridView.Rows[k].Cells[dataGridView.Columns[column].Name].Value.ToString() == column)
{
}
else
{
//MessageBox.Show("COLUMN" + dataGridView.Columns[j].Name.ToString() + "" + dataGridView.Rows[k].Cells[column].Value.ToString() + " NOT A DECIMAL!");
sb.AppendLine("[Column " + chk[j].Name.ToString().ToUpper() + "] :" + dataGridView.Rows[k].Cells[column].Value.ToString() + " NOT A DECIMAL!");
}
}
}
sb.AppendLine("");
}
}
if (sb.ToString() == null || sb.ToString() == "" || sb.Length < dataGridView.Columns.Count)
{
sw.WriteLine("No Errors!");
sw.WriteLine("");
sw.WriteLine("----------------------------");
MessageBox.Show("No errors!");
Process.Start(#"C:\brandon\InvalidColumnCheck.txt");
}
else if (sb.ToString() != null || sb.ToString() != "")
{
sw.WriteLine(sb.ToString());
sw.WriteLine("----------------------------");
//MessageBox.Show(sb.ToString());
Process.Start(#"C:\brandon\InvalidColumnCheck.txt");
}
sw.Flush();
sw.Close();
}
Here another way to get all Checkboxes from Panel, which are checked (with Linq):
List<CheckBox> selectedItems = panelCol.Controls.OfType<CheckBox>().Where(chk => chk.Checked).ToList();
Please change the validation method like below,
public List<CheckBox> GetSelectedItems()
{
List<CheckBox> selectedList = new List<CheckBox>();
foreach(Control control in panelCol.Controls) // panelCol is your panel
{
if(control is CheckBox)
{
CheckBox chkCtrl = control as CheckBox;
if(chkCtrl.Checked)
{
selectedList.Add(chkCtrl);
}
}
}
return selectedList;
}
btnValidate.MouseClick += (s, e) =>//btnValidate Event
{
List<CheckBox> selectedItems = GetSelectedItems();
if(selectedItems.Count == 0)
MessageBox.Show("Select a CheckBox!");
else{
// Continue with other validation for the selected checkboxes from the list
}
}
Hope it helps!
I am trying to make a cell change colour when its value is under 100 however it does not change the color of the cell. I can default the colour of the entire grid however it is not working for individual cells. Please can someone lend a hand?
Here is the code I have so far:
connection.Open();
var SinglesDataTable = new DataTable();
adapter.Fill(SinglesDataTable);
connection.Close();
DataColumn hourlyavg = SinglesDataTable.Columns.Add("Hourly Average", typeof(String));
for (int i = 0; i < SinglesDataTable.Rows.Count; i++)
{
object pickvalue = SinglesDataTable.Rows[i][1].ToString();
object timevalue = SinglesDataTable.Rows[i][2].ToString();
double pickval1 = Convert.ToDouble(pickvalue);
string timeS = "";
timeS = timevalue.ToString();
string timeSTrimmed = (timeS.Replace(":", ""));
string timeSTrimmedHoursMins = (timeSTrimmed.Remove(timeSTrimmed.Length - 2));
string timehourminindecimal = timeSTrimmedHoursMins.Insert(2, ".");
double timeint = Convert.ToDouble(timehourminindecimal);
if (timeint < 1)
{
timeint = Math.Ceiling(timeint);
}
else
{
timeint = timeint;
}
Convert.ToInt32(pickvalue);
var hourlyratevar = pickval1 / timeint;
double hourlyratedouble = Math.Round(hourlyratevar, 2);
int hourlyraterounded = (int)Math.Ceiling(hourlyratedouble);
SinglesDataTable.Rows[i][3] = hourlyraterounded;
string hourlyavgstring = SinglesDataTable.Rows[i][3].ToString();
double hourlyavgint = Convert.ToDouble(hourlyavgstring);
foreach (DataGridViewRow row in SinglesGridView.Rows)
if (Convert.ToInt32(row.Cells[1].Value) > 100)
{
row.DefaultCellStyle.BackColor = Color.Red;
}
SinglesGridView.DataSource = SinglesDataTable;
foreach (DataGridViewRow row in SinglesGridView.Rows)
if (Convert.ToInt32(row.Cells[1].Value) > 100)
row.Cells[1].Style.BackColor = Color.Red;
there is another option: handle CellPainting event of DataGridView. E.g.:
private void SinglesGridView_CellPainting(object sender,
System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == 1 &&
e.RowIndex >= 0 &&
Convert.ToInt32(SinglesGridView[e.ColumnIndex, e.RowIndex].Value) > 100)
e.CellStyle.BackColor = Color.Red;
}
I am adding controls to a form dynamically, then reading back the responses. To do this, I have to recreate the form on postback before trying to get at the responses.
At present, only fields that require a date have an AjaxControlToolkit MaskedEditExtender:
case "DAT":
TextBox tb = new TextBox();
tb.ID = "tbDat" + intQuestionCount.ToString();
tb.CssClass = "PositionCol3 SVSTextBox1";
tb.Width = 250;
// check for date range restricdtions and display in tooltip
strTooltip = "";
if (question.DateMaxDaysInPast != 0)
{
DateTime dtPastDate = DateTime.Now.AddDays(-Convert.ToInt32(question.DateMaxDaysInPast));
strTooltip = "Date must be after " + dtPastDate.ToShortDateString();
}
if (question.DateMaxDaysInFuture != 0)
{
DateTime dtFutureDate = DateTime.Now.AddDays(Convert.ToInt32(question.DateMaxDaysInFuture));
if (strTooltip == "")
{
strTooltip = "Date must be before " + dtFutureDate.ToShortDateString();
}
else
{
strTooltip += " and before " + dtFutureDate.ToShortDateString();
}
}
tb.ToolTip = strTooltip; ;
// if this is a completed form look for saved response
if (intCompletedSurveyAnswerId != 0)
{
tb.Text = strAnswerText;
}
questionsPanel.Controls.Add(tb);
// add to list of controls
m_orderOfControls[intNumOfControls] = "TB";
intNumOfControls += 1;
// add to saved textboxes
m_dynamicTextBoxes[intTextBoxCount] = tb;
intTextBoxCount += 1;
// try add masked edit extender
AjaxControlToolkit.MaskedEditExtender maskedEdit = new AjaxControlToolkit.MaskedEditExtender();
maskedEdit.ID = "mk_" + tb.ID;
maskedEdit.TargetControlID = tb.ID;
maskedEdit.Mask = "99/99/9999";
maskedEdit.MaskType = AjaxControlToolkit.MaskedEditType.Date;
//maskedEdit.InputDirection = AjaxControlToolkit.MaskedEditInputDirection.RightToLeft;
questionsPanel.Controls.Add(maskedEdit);
// add to list of controls
m_orderOfControls[intNumOfControls] = "MK";
intNumOfControls += 1;
// add to saved textboxes
m_dynamicMasks [intMaskCount] = maskedEdit;
intMaskCount += 1;
break;
m_orderOfControls, intNumOfControls, m_dynamicMasks, intMaskCount are all save as session vaiables, so that the form can be recreated on postback:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
retrieveDynamicControlsFromSession();
recreateForm();
}
and:
protected void recreateForm()
{
//
// Form needs to be recreated after postback exactly as want sent out
//
try
{
int intNumOfLabels = 0;
int intNumOfTextBoxes = 0;
int intNumDdls = 0;
int intNumCbls = 0;
int intNumRbls = 0;
int intNumCbs = 0;
int intNumLitControls = 0;
int intNumMaskedEditExtenders = 0;
questionsPanel.Controls.Clear();
foreach (string controlType in m_orderOfControls)
{
if (controlType != null)
{
LiteralControl htmlControl = new LiteralControl();
switch (controlType)
{
case "MK":
AjaxControlToolkit.MaskedEditExtender maskedEdit = new AjaxControlToolkit.MaskedEditExtender();
maskedEdit = m_dynamicMasks[intNumMaskedEditExtenders];
intNumMaskedEditExtenders += 1;
questionsPanel.Controls.Add(maskedEdit);
break;
case "LB":
Label lbl = new Label();
lbl = m_dynamicLabels[intNumOfLabels];
intNumOfLabels += 1;
questionsPanel.Controls.Add(lbl);
break;
case "TB":
TextBox textBox = new TextBox();
textBox = m_dynamicTextBoxes[intNumOfTextBoxes];
intNumOfTextBoxes += 1;
questionsPanel.Controls.Add(textBox);
break;
case "CB":
CheckBox checkBox = new CheckBox();
checkBox = m_dynamicCheckBoxes[intNumCbs];
intNumCbs += 1;
questionsPanel.Controls.Add(checkBox);
break;
case "CBL":
CheckBoxList checkBoxList = new CheckBoxList();
checkBoxList = m_dynamicCheckBoxLists[intNumCbls];
intNumCbls += 1;
questionsPanel.Controls.Add(checkBoxList);
break;
case "RBL":
RadioButtonList radioButtonList = new RadioButtonList();
radioButtonList = m_dynamicRadioButtonLists[intNumRbls];
intNumRbls += 1;
questionsPanel.Controls.Add(radioButtonList);
break;
case "HTML":
LiteralControl hmtlControl = new LiteralControl();
htmlControl = m_literalControls[intNumLitControls];
intNumLitControls += 1;
questionsPanel.Controls.Add(htmlControl);
break;
case "DDL":
DropDownList dropDownList = new DropDownList();
dropDownList = m_dynamicDropDownLists[intNumDdls];
intNumDdls += 1;
questionsPanel.Controls.Add(dropDownList);
break;
default:
break;
}
// end paragraph
}
}
}
catch (Exception ex)
{
throw ex;
}
}
On testing this, after form Save button has been used once or twice, I get this error: Extender controls may not be registered after PreRender.
Any ideas?
I'm using Epplus to render an Excel spreadsheet into HTML. So far it's going very, very well, except for one thing... spanning merged cells. I just can't seem to get the logic right. I thought I would throw it out there to see how the community would deal with it. Here is my code so far.
public String ParseExcelStamps(String FileName)
{
FileInfo theFile = new FileInfo(FileName);
String html = "";
using (ExcelPackage xlPackage = new ExcelPackage(theFile))
{
var workbook = xlPackage.Workbook;
if (workbook != null)
{
for (int j = 1; j <= workbook.Worksheets.Count; j++)
{
Tab tab = new Tab();
html+= "<table style='border-collapse: collapse;font-family:arial;'><tbody>";
var worksheet = workbook.Worksheets[j];
tab.Title = worksheet.Name;
if (worksheet.Dimension == null) { continue; }
int rowCount = 0;
int maxColumnNumber = worksheet.Dimension.End.Column;
var convertedRecords = new List<List<string>>(worksheet.Dimension.End.Row);
var excelRows = worksheet.Cells.GroupBy(c => c.Start.Row).ToList();
excelRows.ForEach(r =>
{
rowCount++;
html += String.Format("<tr>");
var currentRecord = new List<string>(maxColumnNumber);
var cells = r.OrderBy(cell => cell.Start.Column).ToList();
Double rowHeight = worksheet.Row(rowCount).Height;
for (int i = 1; i <= maxColumnNumber; i++)
{
var currentCell = cells.Where(c => c.Start.Column == i).FirstOrDefault();
//look aheads for colspan and rowspan
ExcelRangeBase previousCellAbove = null;
ExcelRangeBase previousCell = null;
ExcelRangeBase nextCell = null;
ExcelRangeBase nextCellBelow = null;
try { previousCellAbove = worksheet.Cells[rowCount-1, i]; }catch (Exception) { }
try { previousCell = worksheet.Cells[rowCount, (i - 1)]; }catch (Exception) { }
try { nextCell = worksheet.Cells[rowCount, (i + 1)]; }catch (Exception) { }
try { nextCellBelow = worksheet.Cells[rowCount+1, i]; }catch (Exception) { }
if ((previousCell != null) && (previousCell.Merge) && (currentCell != null) && (currentCell.Merge)){continue;}
if ((previousCellAbove != null) && (previousCellAbove.Merge) && (currentCell != null)) {continue; }
if (currentCell == null)
{
html += String.Format("<td>{0}</td>", String.Empty);
}
else
{
int colSpan = 1;
int rowSpan = 1;
if ((nextCell != null) && (nextCell.Merge) && (currentCell.Merge)) {
colSpan = 2;
// Console.WriteLine(String.Format("{0} - {1}", currentCell.Address, nextCell.Address));
}
if ((nextCellBelow != null) && (nextCellBelow.Merge) && (currentCell.Merge)) {
Console.WriteLine(String.Format("{0} - {1}", currentCell.Address, nextCellBelow.Address));
}
html += String.Format("<td colspan={0} rowspan={1}>{2}</td>", colSpan, rowSpan, currentCell.Value);
}
}
html += String.Format("</tr>");
});
html += "</tbody></table>";
}//worksheet loop
}
}
return html;
}
As far as I can tell this is exactly what you need. What you were missing was the MergedCells property on the worksheet which lists all merged cells in the sheet.
My code handles row spans, column spans, and both at the same time. I did some testing with a spreadsheet that included both row, column and row/column spanning. In all cases they worked perfectly.
Code
int colSpan = 1;
int rowSpan = 1;
//check if this is the start of a merged cell
ExcelAddress cellAddress = new ExcelAddress(currentCell.Address);
var mCellsResult = (from c in worksheet.MergedCells
let addr = new ExcelAddress(c)
where cellAddress.Start.Row >= addr.Start.Row &&
cellAddress.End.Row <= addr.End.Row &&
cellAddress.Start.Column >= addr.Start.Column &&
cellAddress.End.Column <= addr.End.Column
select addr);
if (mCellsResult.Count() >0)
{
var mCells = mCellsResult.First();
//if the cell and the merged cell do not share a common start address then skip this cell as it's already been covered by a previous item
if (mCells.Start.Address != cellAddress.Start.Address)
continue;
if(mCells.Start.Column != mCells.End.Column) {
colSpan += mCells.End.Column - mCells.Start.Column;
}
if (mCells.Start.Row != mCells.End.Row)
{
rowSpan += mCells.End.Row - mCells.Start.Row;
}
}
//load up data
html += String.Format("<td colspan={0} rowspan={1}>{2}</td>", colSpan, rowSpan, currentCell.Value);
I have a dhtmlgoodies_calendar in my asp.net application and have made some changes to the writeCalendarContent method to disable the dates in the past. It works fine on Internet explorer. But in firefox and chrome the dates in the past are still displayed anyways.
Does anybody have any idea in how to make this work in those browers?
any help is appreciated.
Thanks
Here is my method:
function writeCalendarContent()
{
var blockDateInPast = true;
var calendarContentDivExists = true;
if(!calendarContentDiv){
calendarContentDiv = document.createElement('DIV');
calendarDiv.appendChild(calendarContentDiv);
calendarContentDivExists = false;
}
currentMonth = currentMonth/1;
var d = new Date();
var data = new Date();
var AnoAtual = data.getYear();
var MesAtual = data.getMonth();
var DiaAtual = data.getDate();
d.setFullYear(currentYear);
d.setDate(1);
d.setMonth(currentMonth);
var dayStartOfMonth = d.getDay();
if (! weekStartsOnSunday) {
if(dayStartOfMonth==0)dayStartOfMonth=7;
dayStartOfMonth--;
}
document.getElementById('calendar_year_txt').innerHTML = currentYear;
document.getElementById('calendar_month_txt').innerHTML = monthArray[currentMonth];
document.getElementById('calendar_hour_txt').innerHTML = currentHour;
document.getElementById('calendar_minute_txt').innerHTML = currentMinute;
var existingTable = calendarContentDiv.getElementsByTagName('TABLE');
if(existingTable.length>0){
calendarContentDiv.removeChild(existingTable[0]);
}
var calTable = document.createElement('TABLE');
calTable.width = '100%';
calTable.cellSpacing = '0';
calendarContentDiv.appendChild(calTable);
var calTBody = document.createElement('TBODY');
calTable.appendChild(calTBody);
var row = calTBody.insertRow(-1);
row.className = 'calendar_week_row';
if (showWeekNumber) {
var cell = row.insertCell(-1);
cell.innerHTML = weekString;
cell.className = 'calendar_week_column';
cell.style.backgroundColor = selectBoxRolloverBgColor;
}
for(var no=0;no<dayArray.length;no++){
var cell = row.insertCell(-1);
cell.innerHTML = dayArray[no];
}
var row = calTBody.insertRow(-1);
if (showWeekNumber) {
var cell = row.insertCell(-1);
cell.className = 'calendar_week_column';
cell.style.backgroundColor = selectBoxRolloverBgColor;
var week = getWeek(currentYear,currentMonth,1);
cell.innerHTML = week; // Week
}
for(var no=0;no<dayStartOfMonth;no++){
var cell = row.insertCell(-1);
cell.innerHTML = ' ';
}
var colCounter = dayStartOfMonth;
var daysInMonth = daysInMonthArray[currentMonth];
if(daysInMonth==28){
if(isLeapYear(currentYear))daysInMonth=29;
}
for(var no=1;no<=daysInMonth;no++){
d.setDate(no-1);
if(colCounter>0 && colCounter%7==0){
var row = calTBody.insertRow(-1);
if (showWeekNumber) {
var cell = row.insertCell(-1);
cell.className = 'calendar_week_column';
var week = getWeek(currentYear,currentMonth,no);
cell.innerHTML = week; // Week
cell.style.backgroundColor = selectBoxRolloverBgColor;
}
}
var cell = row.insertCell(-1);
if (currentYear<AnoAtual && blockDateInPast==true)
{
cell.className='DesactiveDay';
cell.onclick = null;
}
else if (currentYear==AnoAtual)
{
if (currentMonth < MesAtual && blockDateInPast == true)
{
cell.className='DesactiveDay';
cell.onclick = null;
}
else if (currentMonth==MesAtual)
{
if (no < DiaAtual && blockDateInPast == true)
{
cell.className='DesactiveDay';
cell.onclick = null;
}
else
{
cell.onclick = pickDate;
}
}
else
{
cell.onclick = pickDate;
}
}
else
{
cell.onclick = pickDate;
}
if (cell.onclick == pickDate)
{
if(currentYear==inputYear && currentMonth == inputMonth && no==inputDay){
cell.className='activeDay';
cell.onclick = pickDate;
}
}
cell.innerHTML = no;
colCounter++;
}
if(!document.all){
if(calendarContentDiv.offsetHeight)
document.getElementById('topBar').style.top = calendarContentDiv.offsetHeight + document.getElementById('timeBar').offsetHeight + document.getElementById('topBar').offsetHeight -1 + 'px';
else{
document.getElementById('topBar').style.top = '';
document.getElementById('topBar').style.bottom = '0px';
}
}
if(iframeObj){
if(!calendarContentDivExists)setTimeout('resizeIframe()',350);else setTimeout('resizeIframe()',10);
}
}
Just add following code at the end of writeCalendarContent(),
if(currentYear==inputYear && currentMonth == inputMonth && no==inputDay){
cell.className='activeDay';
cell.onclick = pickDate;
}
else if(currentYear<inputYear || currentMonth < inputMonth || no<inputDay){
cell.className = 'inactive-date';
}
else{
cell.onclick = pickDate;
}
cell.innerHTML = no;
colCounter++;
It adds the click event only for current date and next dates. It doesn't add click for past dates. You can add style for past dates(add style for inactive-date class).
Not at all, this following code is correct and tested
if(disabledDateInPast){
var now = new Date();
var yearOfNow = now.getFullYear();
var monthOfNow = now.getMonth();
var noOfNow = now.getDate();
if(currentYear < yearOfNow){
cell.className = 'desactiveDay';
}
else if(currentYear > yearOfNow){
cell.onclick = pickDate;
}
else if (currentYear == yearOfNow){
if(currentMonth < monthOfNow){
cell.className = 'desactiveDay';
}
else if(currentMonth > monthOfNow){
cell.onclick = pickDate;
}
else if(currentMonth == monthOfNow){
if(no < noOfNow){
cell.className = 'desactiveDay';
}
else{
cell.onclick = pickDate;
}
}
}
}
else{
cell.onclick = pickDate;
}
if(currentYear==inputYear && currentMonth == inputMonth && no==inputDay){
cell.className='activeDay';
}