get value from javascript to web control

In my page I have label control

<asp:label id="Label1" runat="server" />

when page load I set that label value using javascript

function setvalue() {
document.getElementById("Label1").innerHTML = "hello"
}
<body onLoad="setvalue();">

and i also have a button. When I click that button, it read the label value

Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
Dim a as string = Label1.Text
end sub

but the problem is variable a always empty or ""
How to solve it?
0
encim
3/30/2004 6:38:13 AM
asp.net.client-side 24353 articles. 1 followers. Follow

5 Replies
759 Views

Similar Articles

[PageSpeed] 41

Change 

1. Asp:Label to Asp:TextBox
2. document.getElementById("Label1").innerHTML = "hello" to document.getElementById("Textbox1").value= "hello"
3. Dim a as string = Label1.Text to Dim a as string = Textbox1.Text
:)
0
encim
3/30/2004 8:59:39 AM
first the server tags get fired and then the javascript tags.

hence, when u click on the button the page goes for post back and so first server work is done and then it goes for client side.
u cannot keep the previous values of labels after the postback.
If u must require it to do so, then u try using a hidden variable.
when u assign value to a label u assign value to hidden variable also.
in the button click u can access the label value through the hiddden variable value as they both are same.
hidden varibale keeps up its value even after postback also.
this is somewhat tiresome
if u can give me ur requirement exactly at what place,
i can give u an easy solution.
bye

Umesh
0
umesh
3/30/2004 9:24:37 AM
here the example


<HTML>
<HEAD>
<script language="javascript">
function init() {
document.getElementById("Label1").innerHTML = "hohoho.. label" ;
document.getElementById("TextBox1").value = "hohoho.. textbox" ;
}

</script>
</HEAD>
<body onload="init();">
<form id="Form1" method="post" runat="server">
<br><asp:Label ID="Label1" Runat="server" />
<br><asp:TextBox ID="TextBox1" Runat="server" />
<br><asp:Button ID="Button1" Runat="server" Text="Submit" />
<br><asp:Label ID="Label2" Runat="server" />
</form>
</body>
</HTML>

here is the code behind

Public Class test
Inherits System.Web.UI.Page
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
#Region " Web Form Designer Generated Code "
... cut.. cut...
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label2.Text = Label1.Text & TextBox1.Text
End Sub
End Class

in this condition. Label1.Text always empty
Actually I can solve my problem by replacing Label with Textbox, but I (and all of us) want to know your easy solution
0
encim
3/31/2004 3:14:57 AM
try this.

i think we need the use of hidden variable.

<script language="javascript">
function funinit()
{
document.getElementById("label1").innerHTML="Umesh";
document.getElementById("text1").value="Ramesh";
document.Form1.hdnText.value=document.getElementById("label1").innerHTML;
}
</script>

<body MS_POSITIONING="GridLayout" onload="javascript:funinit();">
<form id="Form1" method="post" runat="server">
<asp:Label ID="label1" Runat="server"></asp:Label><br>
<asp:textbox ID="text1" Runat="server"></asp:textbox><br>
<asp:Label ID="label2" Runat="server"></asp:Label><br>
<asp:Button ID="btnSubmit" Text="Submit" Runat="server"></asp:Button>
<input type="hidden" runat="server" id="hdnText">
</form>
</body>


Umesh
0
umesh
3/31/2004 6:32:23 AM
hm... that is better and more flexible

thanks
0
encim
4/1/2004 2:50:47 AM
Reply:

Similar Artilces:

Question re: accessing web control values via client-side javascript
This block of variables gets generated dynamically from my _PreRender event of my formView : <SCRIPT Language='JavaScript'>  var chkInvertAliasID = 'ctl00_ContentPlaceHolder1_FormView1_chkEditInvert';  var chkAct_CurAliasID = 'ctl00_ContentPlaceHolder1_FormView1_chkEditAct_Cur';  var radBuy_SellAliasID = 'ctl00_ContentPlaceHolder1_FormView1_radioEditBuySell'; </SCRIPT> Now on the client-side I get a handle to above-declared var's : function QuoteConvention(obj) {         var objChkInvert = document.getElementById(chkInv...

How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

Get value of a client-side control
i have a webcontrol that has 2 viewstate variables and in the render event handler i write them as hidden input fields, because i need to be able to change them in javascript. the problem is, how can i access the changes made by the javascript? the control is actually a calendar written out as an html table and has 2 links for next/previous month which call javascript functions to change the month and then the table is updated with the new month (with AJAX). now, in my function that gets called an raisecallbackevent i need to know the values of the new month/year so that the javascript can c...

Getting Value from Client-side InputBox to .net variable
hi, im doing a login page for our timekeeping. Since there's no msgbox available on asp.net, im doing it dynamically via javascript. How do i Get the value frm a dynamically written javascript (such as inputbox) to a .net variable? here's the logic of my program, user logs in hits the button and sub-routine Login will be fired, if user is late -- call Check_Late Sub, this is whre the client-side script was built -- then after that i wanted to be able to get the value from an inputbox. '// if button login clicked Sub Login(Sender As Object, E As EventArgs) .......

How do I get value of web control within clientside javascript for customvalidator
Hello, I'm using the following java script to validate if the selected value in one radiobuttonlist (radBenutertyp) fits to certain value of another radiobuttonlist (radFirma):<script type="text/javascript">         function vcsBenutzertyp_ClientValidate(sender, e)             {                var Usertype = e.Value;               ...

Running javascript client side code from a web server control
Hi, I need to execute some client side javascript code from an asp.net server side control. For example, in an asp.net button server control I have code for server side click event and also code for onclientclick property. However, the code in the onclientclick property does not run. What is the correct way to execute javascript code from an asp.net server control? Regards, Sandyhttp://www.thequinn.infohttp://www.sksdataservices.comhttp://www.infobasket.info What you want to do actually? You can add attributes to the server control on page_load or use the ClientScript blocks. To add attr...

how can i add client side javascript to a web user control?
i want to create a simple calculator so i have tried to create web user control "hesapmak.ascx" and insert hesapmak.ascx but it is not working i can't find solution? help me?    hesapmak.ascx <%@ Control Language="C#" AutoEventWireup="true" CodeFile="hesapmak.ascx.cs" Inherits="hesapmak" %><asp:WebPartManager ID="WebPartManager1" runat="server"> </asp:WebPartManager> <asp:WebPartZone ID="WebPartZone1" runat="server" Width="184px" BackColor="SandyB...

Get the Dropdownlist text and value using Javascript from client side
Hi, I am encountering a problem about how to get the Dropdownlist text and value using Javascript from client side. I am using C# in Visual Studio 2005 and Javasript . The example codes are like: ( In this example code, I would like to access the text and value of the DropDownListReports in the run() function of Javascript. How can I do that? Any ideas? Thanks a lot. ) protected void Page_Load(object sender, EventArgs e) {              if (!Page.IsPostBack)            &nb...

Disabling a TextBox web control using javascript (client-side)
I'm using two textboxes and one button for a C# .NET web app code: <form id="Form1" method="post" runat="server"> <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 248px; POSITION: absolute; TOP: 128px" runat="server"></asp:TextBox> <asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 248px; POSITION: absolute; TOP: 168px" runat="server"></asp:TextBox> <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 248px; POSITION: absolute; TO...

How to get control value changed by javascript unload event in server side?
I use javascript to change the value of a HtmlInputHidden control during window.onunload event. However, the ASP.NET server side code can only get the value before the change. How can this be solved?   Hi, the clientside event "onunload" occurs at all times when the user navigate to a new page. A postback is not effected every time after the onunload event. Try to use the onsubmit event and attach an event method at the end of the page, e.g.: </body> <script> window.document.form1.attachEvent("onsubmit", SetValue); </script> </html>RegardsMarc A...

Javascript : how to get web control value in content page from popup window
Hi all,I have 2 pages : First.aspx & Second.aspx. Second.aspx is a popup window which be launched from First.aspx. Second.aspx passes a value to a control in First.aspx --- Javascript of First.aspx ---  function PassTextToChild()     {        var passVal = document.getElementById('<%=TextBox1.ClientID%>').value;        var url = "Second.aspx?Value="+passVal;        window.open(url, "", "width=400,height=200,toolbar=no,scr...

Please help : question on how to reference web controls from client-side Javascript .
Folks,  I have some simple Javascript here that needs to reference not only aCheckBox object being passed as a parameter, but also various otherfields on my web page. My main question is HOW do I access/manipulate controls withclient-side script ? I know how to access the value of the Checkbox because I pass it to myjavascript function like this : QuoteConv(this) . However, since Asp2.0 renames all the ID properties of my web controls, what's the bestway to reference all the various controls (i.e. html TextBox, checkbox,radio, etc) ???Here's the beginning of my aspx page with...

Web User Control +Client Side Control
Two Questions if Possible:  1: Some controls have methods/properties that can be gotten/set client-side (IE ASP:Timer).  Can usally access them by "$find('<%=Control.ClientID%>').get_(set_)name()".  I made a User Control that has a "Enabled" Propertiy (basically sets a bunch of its components to "visible = false" and then a Timer.Enabled=false).  I can't access my user controls "enabled" via client side script (IE $find(UserControl.ClientID).set_enabled(false)).  How do I bundle this type of fu...

how to get value from client side script Prompt window to a session var in .net
hi guyz, i hav a problem with getting a value from a client-side inputbox to a session var in .net. is this possible? however, when i click submit button this is the code that's triggered. dim sb as New System.Text.StringBuilder sb.append("<script language=" & """" & "vbscript" & """" & ">") sb.append(vbcrlf) sb.append(vbcrlf) sb.append("do while xLate =" & """" & """") sb.append(vbcrlf) '//prompt window, val...

Web resources about - get value from javascript to web control - asp.net.client-side

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

JavaScript - Wikipedia, the free encyclopedia
programming styles. JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
... editor - report abuse/spam - help the entire directory only in Tools/Obfuscators Description Top : Computers : Programming : Languages : JavaScript ...

Facebook File-Transfer App Pipe Relaunches, Now Works Via JavaScript, WebRTC
... allowed Facebook users to send and receive files up to 1 gigabit in size. A new version of Pipe debuted Monday, and the app now works via JavaScript ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript
The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing ...

Senior Front-End Developer (Javascript and AJAX)
Company: Sometrics Category: Software Development Location: Los Angeles, CA How to Apply: jobs@sometrics.com Description: We are looking for ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken . blog.mozilla.org/research/2014/… ...

Resources last updated: 1/17/2016 11:53:12 AM