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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. .net javascript masterpage conflict

.net javascript masterpage conflict

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-nethelpquestion
6 Posts 3 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.
  • J Offline
    J Offline
    janetb99
    wrote on last edited by
    #1

    I'm not a Javascript person, so please be kind. I've got an asp.net 2 page that has a master page. I've got a javascript that works fine in a regular asp.net page within the same web. Move it to the page with the master page, and it won't work. Any help appreciated. Also, what's the difference between function setDifference(form) and setDifference = function(form)? Here's the basic stuff:

    setDifference = function(form)
    {
    var x = document.getElementById('dtTxt1').value;
    var y = document.getElementById('dtTxt2').value;
    var dt1 = Date.parse(x)
    var dt2 = Date.parse(y)
    document.getElementById('resultTxt').value = (dt1.valueOf() - dt2.valueOf()) / (60 * 60 * 24 * 1000)
    }

    C S 2 Replies Last reply
    0
    • J janetb99

      I'm not a Javascript person, so please be kind. I've got an asp.net 2 page that has a master page. I've got a javascript that works fine in a regular asp.net page within the same web. Move it to the page with the master page, and it won't work. Any help appreciated. Also, what's the difference between function setDifference(form) and setDifference = function(form)? Here's the basic stuff:

      setDifference = function(form)
      {
      var x = document.getElementById('dtTxt1').value;
      var y = document.getElementById('dtTxt2').value;
      var dt1 = Date.parse(x)
      var dt2 = Date.parse(y)
      document.getElementById('resultTxt').value = (dt1.valueOf() - dt2.valueOf()) / (60 * 60 * 24 * 1000)
      }

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

      This is creating a function, which takes form as a parameter, and is called setDifference. I don't think in this instance that it would matter if you removed the = function part. I could be wrong, I am no JS master, either. What does 'won't work' mean, do you get any errors ? Have you tried using firebug in firefox to debug the script ?

      Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

      J 1 Reply Last reply
      0
      • C Christian Graus

        This is creating a function, which takes form as a parameter, and is called setDifference. I don't think in this instance that it would matter if you removed the = function part. I could be wrong, I am no JS master, either. What does 'won't work' mean, do you get any errors ? Have you tried using firebug in firefox to debug the script ?

        Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

        J Offline
        J Offline
        janetb99
        wrote on last edited by
        #3

        Christian, Won't work means that no calculation takes place. Nothing happens. And, as I'm really unfamiliar with Javascript, don't know how to use Firebug in Firefox to debug. Janet

        C 1 Reply Last reply
        0
        • J janetb99

          Christian, Won't work means that no calculation takes place. Nothing happens. And, as I'm really unfamiliar with Javascript, don't know how to use Firebug in Firefox to debug. Janet

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

          The easiest way to debug is to use alert statements, as in alert("I got this far); or alert("The value of X = " + x); This will create popup messages. Also, the browser will show you if it thinks there was a js error. So, I'd start with an alert at the top of the function, telling you if it got called or not. Firebug is an add in for firefox, it lets you set breakpoints in your js and step through. It's awesome. I would say best guess is that where your script is going, the scope means it doesn't get called, but it's best to go through and make sure that is true.

          Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

          1 Reply Last reply
          0
          • J janetb99

            I'm not a Javascript person, so please be kind. I've got an asp.net 2 page that has a master page. I've got a javascript that works fine in a regular asp.net page within the same web. Move it to the page with the master page, and it won't work. Any help appreciated. Also, what's the difference between function setDifference(form) and setDifference = function(form)? Here's the basic stuff:

            setDifference = function(form)
            {
            var x = document.getElementById('dtTxt1').value;
            var y = document.getElementById('dtTxt2').value;
            var dt1 = Date.parse(x)
            var dt2 = Date.parse(y)
            document.getElementById('resultTxt').value = (dt1.valueOf() - dt2.valueOf()) / (60 * 60 * 24 * 1000)
            }

            S Offline
            S Offline
            Spunky Coder
            wrote on last edited by
            #5

            When using the master pages, the form elements get rendered with different ID's...I mean to say 'dtTxt1' will be rendered as something 'ctl00_dtTxt1'. You need to check whether the element ID's that are being used actually exist in the page or not. :) So try the following... var x = document.getElementById('ctl00_dtTxt1').value; var y = document.getElementById('ctl00_dtTxt2').value; But before doing this check if the element ID is actually appended with ct100 or some other value.

            "Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)

            J 1 Reply Last reply
            0
            • S Spunky Coder

              When using the master pages, the form elements get rendered with different ID's...I mean to say 'dtTxt1' will be rendered as something 'ctl00_dtTxt1'. You need to check whether the element ID's that are being used actually exist in the page or not. :) So try the following... var x = document.getElementById('ctl00_dtTxt1').value; var y = document.getElementById('ctl00_dtTxt2').value; But before doing this check if the element ID is actually appended with ct100 or some other value.

              "Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)

              J Offline
              J Offline
              janetb99
              wrote on last edited by
              #6

              Thanks for the reply. I tried that, with no result. I also tried the following in both the master and the child page: var ouptut = document.getElementById('<%= resultTxt.ClientID %>').value; var x = document.getElementById('<%= dtTxt1.ClientID %>').value; var y = document.getElementById('<%= dtTxt2.ClientID %>').value; var dt1 = Date.parse(x) var dt2 = Date.parse(y) output.value = (dt1.valueOf() - dt2.valueOf()) / (60 * 60 * 24 * 1000)

              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