Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey everyone,

How to get value inside a textBox.
Like we do this in C# txtABC.Text.whats in javascript?

And if I've filled my label using javascript client side event,how will I access its value on server side?

It's giving null using lblABC.Text

please help...

Thanks
Amit
Posted
Updated 20-Oct-10 22:08pm
v2
Comments
Dalek Dave 21-Oct-10 4:08am    
Edited for Grammar.

you can use
JavaScript
document.getelementbyid("TextBox1").Value;
:-O


Edit: You missed the quotes and formatting.
 
Share this answer
 
v2
How to get value inside a textBox.
Like we do this in C# txtABC.Text.whats in javascript?


JavaScript
var textboxValue = document.getElementById('TextBox1').value;



And if i've filled my label using javascript client side event,how will i access its value on server side?

Well, the value of a label is not preserved. So a workaround would be to use a hidden field. Here's how:

In the aspx page:
XML
<asp:HiddenField ID="Amount" runat="server" />


Add this line in javascript:
JavaScript
var amt = document.getElementById("Amount");
amt.value = parseInt(txtQuantityE.get_value()) * parseInt(lblRate.innerHTML);
//you may remove the line which assigns this value to label


And in the code behind:
C#
lblAmount.Text = Amount.Value;


Hope this is clear now. :)
 
Share this answer
 
v2
Comments
AmitChoudhary10 20-Oct-10 8:09am    
function show(txtQuantityE, lblRate, lblAmount)
{
var txtQuantityE = $find(txtQuantityE);
var lblRate = document.getElementById(lblRate);
var lblAmount = document.getElementById(lblAmount);
lblAmount.innerHTML = parseInt(txtQuantityE.get_value()) * parseInt(lblRate.innerHTML);
}

if (combo.SelectedIndex > 0 && txtQauntityE.Text != null)
{
DataRow drValues = dtValues.NewRow();
drValues["Items"] = combo.SelectedItem.Text;
drValues["Rate"] = lblRate.Text;
drValues["Quantity"] = txtQauntityE.Text;
drValues["Amount"] = Convert.ToString(lblAmount.Text);
dtValues.Rows.Add(drValues);
dtValues.AcceptChanges();
RadGrid1.DataSource = dtValues;
RadGrid1.Rebind();
RadGrid1.MasterTableView.IsItemInserted = false;
RadGrid1.MasterTableView.Rebind();
}

I am trying to get lblAmount.Text,its coming Null
Ankur\m/ 20-Oct-10 8:41am    
Oh, your question was about label. Label doesn't preserve value. You have to use a hidden field instead. I will update my answer to show how to do it.
AmitChoudhary10 21-Oct-10 1:23am    
But if i'll use Hidden field how will i show the value on the page?...
Ankur\m/ 21-Oct-10 1:32am    
Show it on label itself (using javascript). Also assign it to hidden field so that you can retrieve it in code behind. Label value set using javascript cannot be retrieved in code behind (after post back). So using hidden field will let you get the value in code behind.

Read my answer. Add the code lines that I have given to your existing code. That's it!
And accept the answer if it solves your problem. :)
Dalek Dave 21-Oct-10 4:09am    
Good Answer
you better to start from
JavaScript Tutorial[^]
 
Share this answer
 
jQuery way:

XML
<asp:textbox id="Textbox1" runat="server"/>


jquery
$().ready(function () {
    var value = $('#<%:Texbox1.ClientID %>').Val();
    alert(value);
});


Or a more traditional method:
JavaScript
document.getElementById('<%:Texbox1.ClientID %>').Value;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900