Showing posts with label tick. Show all posts
Showing posts with label tick. Show all posts

Saturday, March 24, 2012

Ajax Timer Tick updating GridView in an unwanted way

I display an empty data set in my gridview by manipulating the gridview to show the headers and a row displaying only No Records Found. Here is the code for that:

if (EQTable.DefaultView.Count == 0)//if filtered data is empty, make sure to show header { EQTable.Rows.Clear(); EQTable.Rows.Add(EQTable.NewRow()); TimeStampGridView.DataSource = EQTable; TimeStampGridView.DataBind();int colNum = TimeStampGridView.Columns.Count; TimeStampGridView.Rows[0].Cells.Clear(); TimeStampGridView.Rows[0].Cells.Add(new TableCell()); TimeStampGridView.Rows[0].Cells[0].ColumnSpan = colNum; TimeStampGridView.Rows[0].Cells[0].Text ="No Records Found."; }

When the timer Tick event goes off is should only check if new data is present by checking the last write time to an xml file. If no new data is present is just returns, On the return, it updates the gridview to show all the cells of the empty row and erases the No Records Found text. Here is the code:

protected void UpdateTimer_Tick(object sender, EventArgs e) {string oldTime = Lb_LastRun.Text;string newTime = GetLastRunTime();if (oldTime != newTime)//doesn't go in for an empty row, but messes up cells of gridview { Lb_LastRun.Text = newTime; EnableExtractorCols(); LoadGrid(); DisableExtractorCols(); } }

Anyone know what I'm doing wrong here? Thanks for the help!!!

I got around this problem by changing the timer tick code:

protected void UpdateTimer_Tick(object sender, EventArgs e)
{
string oldTime = Lb_LastRun.Text;
string newTime = GetLastRunTime();
if (oldTime != newTime)
{
Lb_LastRun.Text = newTime;
EnableExtractorCols();
LoadGrid();
DisableExtractorCols();
}
if (TimeStampGridView.Rows.Count > 0)
{
Label EQLabel = (Label)TimeStampGridView.Rows[0].FindControl("Label1");
if (EQLabel.Text == "")//check for empty row, this is important for displaying headers only on a status filter
{
int colNum = TimeStampGridView.Columns.Count;
TimeStampGridView.Rows[0].Cells.Clear();
TimeStampGridView.Rows[0].Cells.Add(new TableCell());
TimeStampGridView.Rows[0].Cells[0].ColumnSpan = colNum;
TimeStampGridView.Rows[0].Cells[0].Text = "No Equipment Found.";
}
}
}

is there another way to stop this updating?

Ajax Timer & Validators

Hello Everybody,

I have this problem: One page with lots of ASP.NET validation controls and tried to add one AJAX timer that must tick every 20 seconds. My update panel is really simple now, just the timer and a label to show the timer... the problem is that the timer just tick once. I know is due to validation controls 'cause I create a simple test page with just one textbox and a range validator and of course my timer, and after the first tick, it doesn't tick again. I already add this code in the Web.Config for Validators:

<tagMapping>

<addtagType="System.Web.UI.WebControls.CompareValidator"mappedTagType="Sample.Web.UI.Compatibility.CompareValidator, Validators, Version=1.0.0.0"/>

<addtagType="System.Web.UI.WebControls.CustomValidator"mappedTagType="Sample.Web.UI.Compatibility.CustomValidator, Validators, Version=1.0.0.0"/>

<addtagType="System.Web.UI.WebControls.RangeValidator"mappedTagType="Sample.Web.UI.Compatibility.RangeValidator, Validators, Version=1.0.0.0"/>

<addtagType="System.Web.UI.WebControls.RegularExpressionValidator"mappedTagType="Sample.Web.UI.Compatibility.RegularExpressionValidator, Validators, Version=1.0.0.0"/>

<addtagType="System.Web.UI.WebControls.RequiredFieldValidator"mappedTagType="Sample.Web.UI.Compatibility.RequiredFieldValidator, Validators, Version=1.0.0.0"/>

<addtagType="System.Web.UI.WebControls.ValidationSummary"mappedTagType="Sample.Web.UI.Compatibility.ValidationSummary, Validators, Version=1.0.0.0"/>

</tagMapping>

and I added too the Validators.dll... So anyone has an idea of what is missing?

Thanks,

Alejandra

Ok, I solved this problem. I just had to add an "EnableClientValidation = false" to every single validator and it worked, now the timer ticks every 20 seconds... the problem is that I still need to do a couple of Client Validations... hmmm.. I think I would need to do a workaround for this. Any suggestions?

Thanks