foremaro foremaro - 7 months ago 31
Javascript Question

Disabling aspxgridviews on server-side, how to handle on client-side?

I've just started a project where our BA guy needs me to disable all of our aspxgridviews past a certain time.

C#
public void CutoffDateTime()
{
//DateTime today = DateTime.Now; // this will be for live code
DateTime today = new DateTime(2016, 4, 15, 7, 00, 00); // for testing
DateTime cutoff = new DateTime(2016, 4, 19, 7, 00, 00);

if (today >= cutoff.AddDays(7))
{
cutoff = cutoff.AddDays(7);
}
// if today is past cutoff, disable all grids
if (today < cutoff.AddHours(-55))
{
gvProduction.Enabled = false;
gvProductionSummary.Enabled = false;
gvDowntimeSummary.Enabled = false;
gvNonProd.Enabled = false;
cbCutoff.Checked = false;
}
else
cbCutoff.Checked = true;
}


The grids are disabled correctly, but this affects some client-side code that calls the grid.Refresh() methods.

I've added the checkbox as an invisible control so that I can easily interface with the client-side and I'm trying to add:

JS
if (cbCutoff.GetChecked()==true)
grid.Refresh();


But I am still getting JavaScript runtime errors stating that 'cbCutoff is undefined' but I can't think of another way to accomplish this task.

Thanks

EDIT:

Here is part of my asp.net markup that I'm trying to fix via DexExpress' GetChecked() method that returns true if checked:

aspx

<ClientSideEvents ActiveTabChanged="function(s, e) {
if (e.tab.index.toString() == 1 && cbCutoff.GetChecked()==true)
gridProductionSummary.Refresh();
}" />

Answer

Fixed by using

    if (cb.GetChecked())
grid.Refresh();

and set the checkbox to enabled on server-side