to get javactript variable value in code behind
-
on line number i have writen
string val=txtHidden.Value.ToString();
eat is wrong in this? while debuging it is showing the value of txthiden astxtHidden: : System.Web.UI.HtmlControls.HtmlInputHidden
am using .net 2003
OK don't add ToString(); just add string val=txtHidden.Value; And be sure that txtHidden is decalared in your application such as System.Web.UI.HtmlControls.HtmlInputHidden txtHidden;
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
This is the function in javascript
function display() { var localpath1 = document.getElementById('lblerr'); lblerr.innerText = localpath; }
it is diplaying the value on label. lblerr is the id of label. am calling this function on pageload but when i try to get the value using lblerr.text, it is showing null. y is it so? how to get value on the labelP_Elza wrote:
document.getElementById('lblerr');
If this works, odds are that lblerr is not a server control. A server control invariably has a longer client side Id than it's server side one.
Christian Graus - Microsoft MVP - C++ "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 )
-
OK don't add ToString(); just add string val=txtHidden.Value; And be sure that txtHidden is decalared in your application such as System.Web.UI.HtmlControls.HtmlInputHidden txtHidden;
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
that all thing i have written and i have tried this as string val=txtHidden.Value; also befor. it ididnt work that time so i added it to string(); i dont know wat is wrong in my code and y it is not working. why it is taking txtHiddenas "undefined"? i have defined it previously na?
-
that all thing i have written and i have tried this as string val=txtHidden.Value; also befor. it ididnt work that time so i added it to string(); i dont know wat is wrong in my code and y it is not working. why it is taking txtHiddenas "undefined"? i have defined it previously na?
Check the id of the hidden control in aspx page and aspx.cs both should be identical. Could you post your whole page ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Check the id of the hidden control in aspx page and aspx.cs both should be identical. Could you post your whole page ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Text; using System.IO; using System.Data.SqlClient; namespace Web { public class _3B2Temp : System.Web.UI.Page { protected System.Web.UI.WebControls.Button btnclick; protected System.Web.UI.WebControls.Label lblmsg; protected System.Web.UI.WebControls.Label lblerr; protected System.Web.UI.HtmlControls.HtmlInputHidden txtHidden; private void Page_Load(object sender, System.EventArgs e) { } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.btnclick.Click += new System.EventHandler(this.btnclick_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnclick_Click(object sender, System.EventArgs e) { string val=txtHidden.Value; } } }
hope this is enough
-
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Text; using System.IO; using System.Data.SqlClient; namespace Web { public class _3B2Temp : System.Web.UI.Page { protected System.Web.UI.WebControls.Button btnclick; protected System.Web.UI.WebControls.Label lblmsg; protected System.Web.UI.WebControls.Label lblerr; protected System.Web.UI.HtmlControls.HtmlInputHidden txtHidden; private void Page_Load(object sender, System.EventArgs e) { } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.btnclick.Click += new System.EventHandler(this.btnclick_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnclick_Click(object sender, System.EventArgs e) { string val=txtHidden.Value; } } }
hope this is enough
-
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Text; using System.IO; using System.Data.SqlClient; namespace Web { public class _3B2Temp : System.Web.UI.Page { protected System.Web.UI.WebControls.Button btnclick; protected System.Web.UI.WebControls.Label lblmsg; protected System.Web.UI.WebControls.Label lblerr; protected System.Web.UI.HtmlControls.HtmlInputHidden txtHidden; private void Page_Load(object sender, System.EventArgs e) { } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.btnclick.Click += new System.EventHandler(this.btnclick_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnclick_Click(object sender, System.EventArgs e) { string val=txtHidden.Value; } } }
hope this is enough
Please be sure that txtHidden value is assigned in aspx Code looks right check my code this is javascript function function HideContent() { var hiddenVar=document.getElementById('hidden'); hiddenVar.value="Sandeep"; } And here is the .cs file code protected void Page_Load(object sender, EventArgs e) { Button1.Attributes.Add("onclick", "javascript:HideContent();"); } protected void Button1_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(hidden.Value)) { TextBox1.Text = hidden.Value; } } It is working boss in my machine
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
P_Elza wrote:
document.getElementById('lblerr');
If this works, odds are that lblerr is not a server control. A server control invariably has a longer client side Id than it's server side one.
Christian Graus - Microsoft MVP - C++ "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 )
-
Please be sure that txtHidden value is assigned in aspx Code looks right check my code this is javascript function function HideContent() { var hiddenVar=document.getElementById('hidden'); hiddenVar.value="Sandeep"; } And here is the .cs file code protected void Page_Load(object sender, EventArgs e) { Button1.Attributes.Add("onclick", "javascript:HideContent();"); } protected void Button1_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(hidden.Value)) { TextBox1.Text = hidden.Value; } } It is working boss in my machine
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
hi all i have some values on html page in javascript. i want to get that values in C#. how to do that. I tried displaying it on a label, and retreave it from there. but it is displaying the value but label.text is empty. no value in label text.
It may be get by two way 1. Make hidden field and assign your javascript values to that field using javascript. AND then used that hidden field in code behind. 2. Use cookies to get/set values from javascript and codebehind. B'cz as you may know cookies can be operate by javascript and codebehind both side. Prakash Samariya