Unusual behaviour of .net
-
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
-
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
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
-
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
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 -
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 interfaceutsav_verma wrote: x.value=y; Try this instead:
var att = x.attributes.getNamedItem("value");
att.nodeValue = y; -
utsav_verma wrote: x.value=y; Try this instead:
var att = x.attributes.getNamedItem("value");
att.nodeValue = y;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
-
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
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.