Javascript error on empty GridView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vijeberal
    New Member
    • Mar 2008
    • 9

    Javascript error on empty GridView

    Hi all,
    I am working on a GridView and there exist a Checkbox control .. iplaced another checkbox in header also i have written a javascript for selection of checkboxex fro e.g if you click on header checkbox that script will select all the child checkboxes its working fine but when that gridview doesn,t contain anything at that time this script is throwing an error i am sending the code also immidiately help needed
    window.onload = function()
    {
    var gridv=document. getElementById( '<%= this.grvFinAppr oval.ClientID %>');
    TotalChkBx = <%=this.grvFinA pproval.Rows.Co unt%>;
    alert(TotalChkB x);
    Counter = 0;
    }
    function HeaderClick(Che ckBox)
    {
    var TargetBaseContr ol = document.getEle mentById('<%= this.grvFinAppr oval.ClientID %>');
    if(TargetBaseCo ntrol!=null) //not working
    {
    var TargetBaseContr ol = document.getEle mentById('<%= this.grvFinAppr oval.ClientID %>');
    var TargetChildCont rol = "chkFinApproval ";
    var Inputs = TargetBaseContr ol.getElementsB yTagName("input ");
    for(var n = 0; n < Inputs.length; ++n)
    if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(Tar getChildControl ,0) >= 0)
    Inputs[n].checked = CheckBox.checke d;
    Counter = CheckBox.checke d ? TotalChkBx : 0;
    }
    }
    function ChildClick(Chec kBox)
    {
    var HeaderCheckBox = document.getEle mentById('<%= this.grvFinAppr oval.HeaderRow. FindControl("ch kCell").ClientI D %>');
    if(HeaderCheckB ox!=null) //not working
    {
    if(CheckBox.che cked && Counter < TotalChkBx)
    Counter++;
    else if(Counter > 0)
    Counter--;
    if(Counter < TotalChkBx)
    HeaderCheckBox. checked = false;
    else if(Counter == TotalChkBx)
    HeaderCheckBox. checked = true;
    }

    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What is the error message that you get?

    Comment

    • vijeberal
      New Member
      • Mar 2008
      • 9

      #3
      Originally posted by r035198x
      What is the error message that you get?
      System.NullRefe renceException: Object reference not set to an instance of an object.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by vijeberal
        System.NullRefe renceException: Object reference not set to an instance of an object.
        Can you try to get the line (number) where that exception is thrown from?

        Comment

        • vijeberal
          New Member
          • Mar 2008
          • 9

          #5
          Originally posted by r035198x
          Can you try to get the line (number) where that exception is thrown from?
          This is the line in Child_CLick
          var HeaderCheckBox = document.getEle mentById('<%= this.grvFinAppr oval.HeaderRow. FindControl("ch kCell").ClientI D %>');

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Check whether grvFinApproval. HeaderRow.FindC ontrol("chkCell ") is not null by a simple
            Code:
            if(grvFinApproval.HeaderRow.FindControl("chkCell") == null) {
            //output something here to indicate that it's null
            }
            If you get some output from the if then it explains why
            grvFinApproval. HeaderRow.FindC ontrol("chkCell ").ClientID will throw a null reference exception.

            Comment

            • vijeberal
              New Member
              • Mar 2008
              • 9

              #7
              Originally posted by r035198x
              Check whether grvFinApproval. HeaderRow.FindC ontrol("chkCell ") is not null by a simple
              Code:
              if(grvFinApproval.HeaderRow.FindControl("chkCell") == null) {
              //output something here to indicate that it's null
              }
              If you get some output from the if then it explains why
              grvFinApproval. HeaderRow.FindC ontrol("chkCell ").ClientID will throw a null reference exception.
              If we dont show the gridview still this script searching for that checkbox...How do i prevent this searching initiated by javascript

              Comment

              Working...