Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Javascript Error

Javascript Error

Scheduled Pinned Locked Moved ASP.NET
questionjavascripthtmlsysadminhelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samerh
    wrote on last edited by
    #1

    hi all i have a web page and a gridview inside it. In this gridview i added an item template, inside this item template i have a table called table main. Inside table main, in the last tr i have another table called tblOperator and an html button called btnview so the code looks like: <code> <asp:GridView ID="gvRaison" runat="server" AllowPaging="True" AutoGenerateColumns="False" PageSize="5" ShowHeader="False" Width="100%" DataKeyNames="RaisonId" EmptyDataText="No Data found"> <Columns> <asp:TemplateField HeaderText="Name"> <ItemTemplate> <table style="width: 100%;" Id="TableMain" class="TableMain"> <tr>. <tr> <input id="btnview" type="button" onclick="ShowHideTable(this);" value="Show" /> <table id="tblOperator" class="TableMain" style="width: 70%"> </code> i have wrote a javscript function to view/hide the tbloperator function ShowHideTable(args) { if (args.value=='Show') { tblOperator.style.display="block"; args.value= 'Hide'; } else if (args.value=='Hide') { tblOperator.style.display="none"; args.value= 'Show'; } } iam getting an error on this line tblOperator.style.display="none"; the error says tblOperator.style is null or not an object. how can i reference the tblOperator table and set its display?

    C J 2 Replies Last reply
    0
    • S samerh

      hi all i have a web page and a gridview inside it. In this gridview i added an item template, inside this item template i have a table called table main. Inside table main, in the last tr i have another table called tblOperator and an html button called btnview so the code looks like: <code> <asp:GridView ID="gvRaison" runat="server" AllowPaging="True" AutoGenerateColumns="False" PageSize="5" ShowHeader="False" Width="100%" DataKeyNames="RaisonId" EmptyDataText="No Data found"> <Columns> <asp:TemplateField HeaderText="Name"> <ItemTemplate> <table style="width: 100%;" Id="TableMain" class="TableMain"> <tr>. <tr> <input id="btnview" type="button" onclick="ShowHideTable(this);" value="Show" /> <table id="tblOperator" class="TableMain" style="width: 70%"> </code> i have wrote a javscript function to view/hide the tbloperator function ShowHideTable(args) { if (args.value=='Show') { tblOperator.style.display="block"; args.value= 'Hide'; } else if (args.value=='Hide') { tblOperator.style.display="none"; args.value= 'Show'; } } iam getting an error on this line tblOperator.style.display="none"; the error says tblOperator.style is null or not an object. how can i reference the tblOperator table and set its display?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      var tbl = document.getElementById("tblOperator"); if (tbl) { tbl.style.display = "none"; } I believe that window.tblOperator may work, but setting an id does NOT create a global variable of that name.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      S 1 Reply Last reply
      0
      • C Christian Graus

        var tbl = document.getElementById("tblOperator"); if (tbl) { tbl.style.display = "none"; } I believe that window.tblOperator may work, but setting an id does NOT create a global variable of that name.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        S Offline
        S Offline
        samerh
        wrote on last edited by
        #3

        I have already triewd this however it is giving me a design time error that tblOperator is not defined. ur right setting an id does not create a global variable of that name. Any other alternative. thanks

        S 1 Reply Last reply
        0
        • S samerh

          hi all i have a web page and a gridview inside it. In this gridview i added an item template, inside this item template i have a table called table main. Inside table main, in the last tr i have another table called tblOperator and an html button called btnview so the code looks like: <code> <asp:GridView ID="gvRaison" runat="server" AllowPaging="True" AutoGenerateColumns="False" PageSize="5" ShowHeader="False" Width="100%" DataKeyNames="RaisonId" EmptyDataText="No Data found"> <Columns> <asp:TemplateField HeaderText="Name"> <ItemTemplate> <table style="width: 100%;" Id="TableMain" class="TableMain"> <tr>. <tr> <input id="btnview" type="button" onclick="ShowHideTable(this);" value="Show" /> <table id="tblOperator" class="TableMain" style="width: 70%"> </code> i have wrote a javscript function to view/hide the tbloperator function ShowHideTable(args) { if (args.value=='Show') { tblOperator.style.display="block"; args.value= 'Hide'; } else if (args.value=='Hide') { tblOperator.style.display="none"; args.value= 'Show'; } } iam getting an error on this line tblOperator.style.display="none"; the error says tblOperator.style is null or not an object. how can i reference the tblOperator table and set its display?

          J Offline
          J Offline
          J a a n s
          wrote on last edited by
          #4

          Have you checked the source of the rendered page and confirmed the availability of the table? If you make the visibility as false by default, the control wont be rendered to the page. http://www.dustindiaz.com/seven-togglers/[^]

          *jaans

          S 1 Reply Last reply
          0
          • J J a a n s

            Have you checked the source of the rendered page and confirmed the availability of the table? If you make the visibility as false by default, the control wont be rendered to the page. http://www.dustindiaz.com/seven-togglers/[^]

            *jaans

            S Offline
            S Offline
            samerh
            wrote on last edited by
            #5

            yes i did, it exists as tbloperator.

            1 Reply Last reply
            0
            • S samerh

              I have already triewd this however it is giving me a design time error that tblOperator is not defined. ur right setting an id does not create a global variable of that name. Any other alternative. thanks

              S Offline
              S Offline
              Sankar Komma
              wrote on last edited by
              #6

              check what name we are geting in 'tbl'. and also check table,tr and td tags properly closed or not. I found that there are no td tags on your table.

              smile :-)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups