views:

1848

answers:

1

I have a hidden field on my page

<input runat="server" type="hidden" id="selectedIndex" />

and it is being set by this bunch of code, an onclick event to a gridview's row:

var gridViewCtlId = '<%=GridView.ClientID%>';
var selectedIndex = '#<%=selectedIndex.ClientID%>';
var itemVisible = '<%=ItemVisible.ClientID%>';
var gridViewCtl = null;
var curSelRow = null;
var previousRowIndx = null;

window.onload = function showQuery()
{
 if ($(selectedIndex).val() != undefined)
    {
  if ($(selectedIndex).val() != '')
  {
   var prevRowID = $(selectedIndex).val();
   var prevRow = getSelectedRow(prevRowID);
   prevRow.style.backgroundColor = '#1A8CD4';
  }
    }       
}

 function getGridViewControl(rowIdx)
{
    if (gridViewCtl == null)
    {
        gridViewCtl = document.getElementById(gridViewCtlId);
    }
}

function onGridViewRowSelected(rowIdx)
{   
 if (document.getElementById(gridViewCtlId).disabled == false)
 {
  var selRowCCA = getSelectedRow(rowIdx);
  if (curSelRow != null)
  { 
   var previousRow = getSelectedRow(previousRowIndx);

   var CountIdx = previousRowIndx % 2;
   if (document.getElementById(itemVisible) == null)
   {
    if (CountIdx == 0)
    {
     previousRow.style.backgroundColor = 'Silver';
    }
    else
    {
     previousRow.style.backgroundColor = 'White';
    }
   }
  }

  if (null != selRow)
  {
   previousRowIndx = rowIdx;
   curSelRow = selRow;
   selRow.style.backgroundColor = '#1A8CD4';
  }
 }
}
function getSelectedRow(rowIdx)
{
    getGridViewControl(rowIdx);
    if (gridViewCtl != null)
    {
  $(selectedIndex).val(rowIdx);
        return gridViewCtl.rows[rowIdx];
    }
    return null;
}

This is what happens: When The page first loads, the hidden field is undefined, which it should be. When I click on a row and then click the 'select' button which then calls this:

GridView.Attributes.Add("disabled", "true");

The gridview becomes disabled (along with the select button) and another gridview comes up (which should happen depending on what is seleted in the first gridview). So now, here is the problem. When I click on a row in the gridview (I'm only talking about the initial gridview, not the secondary one which comes up, that's not an issue here), and click select, everything gets greyed out and most of the time, the selected row will highlight when the page loads (the other times for some reason it defaults to row #2). Then, say you click on row 4 then click on row 1 and then click select, for some reason row 4 will remain highlighted and row 4's data will then populate the second gridview, like you never clicked row 1. But if I click row 4 then click row 1 then click row 1 again, does it save. Does anyone know why that happens?

Also, I'm pretty much trying to disable the first gridview when select is hit so I do

GridView.Attributes.Add("disabled", "true");

rather than GridView.Enabled = false;

If a user re-clicks the search button (another button located previously on the page which makes this gridview become visible), I would like the secondary gridview to become hidden, and the primary gridview (this one in question) to become re-enabled. But doing

GridView.Attributes.Add("disabled", "false");

when the search button is fired only disables the gridview, which is very weird. Now I know that the disabled field is not supported by any other browser except IE, and i only use it because I need to check if the gridview is disabled so a user cant click on another row after they've made their selection (which happens if I dont do the following:

if (document.getElementById(gridViewCtlId).disabled == false)

So could anyone let me know of another way of accomplishing that task? Thanks again in advance.

+1  A: 

Some bits of info on disabled:

  • Browsers won't send any disabled control's value to the server. This is by definition.
  • Disabled field is supported by other browsers, but it uses a different model. Note list of supported browsers: http://www.w3schools.com/tags/att_input_disabled.asp (also how it is defined disabled='disabled').

Also see how it compares to the read-only: http://www.w3.org/TR/html401/interact/forms.html#h-17.12.2

Also note according to the standard its support its limited to certain elements. This is important, as you are applying it at an unsupported html element, which is also a likely cause of it not working in other browsers in your scenario. You can disable the supported control by using an script, getting the controls to apply it like $get("someClientID").getElementsByTagName("input");

eglasius