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. Unusual behaviour of .net

Unusual behaviour of .net

Scheduled Pinned Locked Moved ASP.NET
csharpjavascripthtmlquestion
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.
  • U Offline
    U Offline
    utsav_verma
    wrote on last edited by
    #1

    Hi, i faced an interesting situation, what i did, i set the value of a label thru javascript, at the click of button i tried to access the valu thru labelname.text, ehh, i didnt get. But when i replace label by text box n set textbox's value thru javascript, i was able to access d value on button click...! Any explanation??? I m taking it as unusual behaviour coz i didnt get any logic behind this sequence. What i observed, in the HTML source code i was able to see textbox's value but label's value was not there...! UTSAV

    C 1 Reply Last reply
    0
    • U utsav_verma

      Hi, i faced an interesting situation, what i did, i set the value of a label thru javascript, at the click of button i tried to access the valu thru labelname.text, ehh, i didnt get. But when i replace label by text box n set textbox's value thru javascript, i was able to access d value on button click...! Any explanation??? I m taking it as unusual behaviour coz i didnt get any logic behind this sequence. What i observed, in the HTML source code i was able to see textbox's value but label's value was not there...! UTSAV

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Labels don't expect their value to be posted back to the server as they are not user changable controls. So the value is not posted back to the server. You probably want to create a hidden control and set the value in there as well. See <INPUT type="HIDDEN">[^] You can then pick up the result from the Request.Form hashtable. ASP.NET 2.0 provides a more elegant solution as there is a specific "Hidden" control.


      My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      U 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Labels don't expect their value to be posted back to the server as they are not user changable controls. So the value is not posted back to the server. You probably want to create a hidden control and set the value in there as well. See <INPUT type="HIDDEN">[^] You can then pick up the result from the Request.Form hashtable. ASP.NET 2.0 provides a more elegant solution as there is a specific "Hidden" control.


        My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

        U Offline
        U Offline
        utsav_verma
        wrote on last edited by
        #3

        Well, first of all, thanks a lot for that bunch of useful information, but here i stucked too, hidden field's value is not retrieved thru Request.Form here is my code - //java script function function OpenWindow() { var prjName=document.getElementById('txtWFPName').getAttribute('value'); if (prjName =="") alert("You have to enter the project name first"); else { var x=document.getElementById('hdRetVal'); var y; alert(x.id); y=window.showModalDialog('../Dbtprs2/PRC/Project_AddNew.aspx?prjname='+prjName,'null','status:no;dialogWidth:350px;dialogHeight:590px;dialogHide:true;help:no;scroll:no'); //x.innerText=y; x.value=y; //x.setAttribute('value',y); alert(x.value); //showing value well } //CS code private void Button1_Click(object sender, System.EventArgs e) { Response.Write("Bingo "+Request.Form["hdRetVal"]); } sorry for bad formatting of code but i m not yet familiar with codeproject's reply interface

        S 1 Reply Last reply
        0
        • U utsav_verma

          Well, first of all, thanks a lot for that bunch of useful information, but here i stucked too, hidden field's value is not retrieved thru Request.Form here is my code - //java script function function OpenWindow() { var prjName=document.getElementById('txtWFPName').getAttribute('value'); if (prjName =="") alert("You have to enter the project name first"); else { var x=document.getElementById('hdRetVal'); var y; alert(x.id); y=window.showModalDialog('../Dbtprs2/PRC/Project_AddNew.aspx?prjname='+prjName,'null','status:no;dialogWidth:350px;dialogHeight:590px;dialogHide:true;help:no;scroll:no'); //x.innerText=y; x.value=y; //x.setAttribute('value',y); alert(x.value); //showing value well } //CS code private void Button1_Click(object sender, System.EventArgs e) { Response.Write("Bingo "+Request.Form["hdRetVal"]); } sorry for bad formatting of code but i m not yet familiar with codeproject's reply interface

          S Offline
          S Offline
          Scott Serl
          wrote on last edited by
          #4

          utsav_verma wrote: x.value=y; Try this instead:

          var att = x.attributes.getNamedItem("value");
          att.nodeValue = y;

          U 1 Reply Last reply
          0
          • S Scott Serl

            utsav_verma wrote: x.value=y; Try this instead:

            var att = x.attributes.getNamedItem("value");
            att.nodeValue = y;

            U Offline
            U Offline
            utsav_verma
            wrote on last edited by
            #5

            YEAH...! It works man it works. THANKS A LOT :D. But can u give me some link which can explain that what i wrote??? I never listen this way to do this task. UTSAV

            S 1 Reply Last reply
            0
            • U utsav_verma

              YEAH...! It works man it works. THANKS A LOT :D. But can u give me some link which can explain that what i wrote??? I never listen this way to do this task. UTSAV

              S Offline
              S Offline
              Scott Serl
              wrote on last edited by
              #6

              Sorry, I hvae no usefull javascript links. I can understand your confusion about accessing attributes. The DOM is quite confusing and I am constanly learning new information. Your code did not work because you were adding a javascript property to your javascript object (javascript is so dynamic, it just lets you do it). Google 'javascript attributes getnameditem' and you will find information about how the DOM treats attributes.

              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