how to get label control value in javascript.

 

Hi I need to get the label Text when the User clicks the browser close button.

function fnPassValues()
{
    if((window.event.clientX < 0) || (window.event.clientY < 0))
    {
       var temp = document.getElementById("<%=lblValue.ClientID%>").innerText;
       alert(temp);
    }
}

If i set the value like this, its working correctly. 

<asp:Label ID="lblValue" Text="3" Height="20px" runat="server" CssClass="clsControl"  style="left: 193px; visibility:hidden; position: relative; top: -25px"/> 

 

But if i set the same via C# code eg: lblValue.Text = 3 ; its not working.., its showing null or the blank popup comes....Can anybody Please Help...?

 

Thanks in Advance. 

0
adarshsk
9/3/2008 2:35:30 PM
asp.net.client-side 24353 articles. 1 followers. Follow

11 Replies
961 Views

Similar Articles

[PageSpeed] 4

Well I just tried this in both IE and Firefox and had no problems.

aspx file:

<asp:Label ID="lblValue" Height="20px" runat="server" CssClass="clsControl"  style="left: 193px; visibility:hidden; position: relative; top: -25px"/>

<script type="text/javascript">
<!--
windowOnBeforeUnload = function ()
{
 if ( (window.event.clientX < 0) || (window.event.clientY < 0) )
 {
  var labelValue = document.getElementById("<%= lblValue.ClientID %>").innerHTML;
  alert(labelValue);
 }
}
window.onbeforeunload = windowOnBeforeUnload;
// -->
</script>

aspx.cs file:

protected void Page_Load(object sender, EventArgs e)
{
    lblValue.Text = "3";
}

NC...

0
NC01
9/3/2008 2:47:13 PM

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ADRoles.aspx.cs" Inherits="CPR.App.Nexus.Web.Admin.Subscriptions.ADRoles" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Manage AD Roles</title>
    <link rel="stylesheet" type="text/css" href="../../AdminStyleSheet.css" />
<script language="javascript" type="text/javascript">

function fnPassValues()
{
    if((window.event.clientX < 0) || (window.event.clientY < 0))
    {
  var labelValue = document.getElementById("<%= lblValue.ClientID %>").innerHTML;
  alert(labelValue);
    }
}

function fnGetValues()
{
    hdntxtSubName.value = window.opener.document.getElementById("txtSubscription").value;
    alert(hdntxtSubName.value);
}

 </script>
</head>
<body onload="fnGetValues()" onunload = "fnPassValues()" ondisposed= "fnPassValues()";>

 

In C# code: after Processing

  public void lnkDelete_Click(object sender, EventArgs e)
        {
            lblStatus.Text = "";
            string strDeleteADRole = Request.QueryString["AD_ROLE_NAME"].ToString();
            string strDeleteStatus = Request.QueryString["Forced_CD"].ToString();

            for (int x = 0; x < dtADRolesInformation.Rows.Count; x++)
            {
                if (dtADRolesInformation.Rows[x][0].ToString() == strDeleteADRole.ToString())
                {
                    dtADRolesInformation.Rows.RemoveAt(x);
                }
            }
            dtADRolesInformation.AcceptChanges();
            daADRolesInformation.Tables.Clear();
            daADRolesInformation.Tables.Add(dtADRolesInformation.Copy());
            daADRolesInformation.AcceptChanges();

            tblADRoleData.Rows.Clear();

            GenerateADRoleReport();

            Response.Redirect("ADRoles.aspx?Response=Deleting", false);
            Session["ADRoleStatus"] = "ADRole Delete Successfull";

            StringBuilder strbldADRoleTable = new StringBuilder();
            foreach (DataRow dr in daADRolesInformation.Tables[0].Rows)
            {
                strbldADRoleTable.Append(dr[0].ToString());
                strbldADRoleTable.Append(',');
                strbldADRoleTable.Append(dr[1].ToString());
                strbldADRoleTable.Append(',');
            }
            Session["ADROLEDATA"] = strbldADRoleTable.ToString();
            if (daADRolesInformation.Tables.Count > 0)
            {
                iADRoleCount = daADRolesInformation.Tables[0].Rows.Count;
            }
            hdntxtadrolelist.Value = iADRoleCount.ToString();
            lblValue.Text = iADRoleCount.ToString();

When i put breakpoint here. it shows three and just after this, if i close the window, blank popup comes

I am using IE6 

If i set the value in Page_Load its working fine, but if i set the value inside delete_click() which is the event of the dynamcially created delete link button....Its not working 

0
adarshsk
9/3/2008 3:32:08 PM

Like I said, I tried it in both IE and Firefox and had no problems so I don't see how I can help unless I waste a tremendous amount of time debugging your code. Sorry.

NC...

 

0
NC01
9/3/2008 3:46:10 PM

Dont use visibility, 

<asp:Label ID="lblValue" Text="3" Height="20px" runat="server" CssClass="clsControl"  style="left: 193px; visibility:hidden; position: relative; top: -25px"/> 

use the following,

<asp:Label ID="lblValue" Text="3" Height="20px" runat="server" CssClass="clsControl"  style="left: 193px; display:none; position: relative; top: -25px"/> 

I hope, you will get your desired result.

Thanks.


HOQUE MD.NAZMUL
[document.getReaders]
0
NHOQUE
9/3/2008 3:46:38 PM

That shouldn't change anything as that is still a client-side attribute. You are thinking of the server-side Visible attribute.

NC...

 

0
NC01
9/3/2008 3:48:39 PM

Thanks all for the valuable Responses

I think the setting of the label text is happening correctly(i checked in debug mode). but its getting reset somewhere by the time i click on the Browser Close Button..... 

Hardcoding the same in page load shows the text/count given correctly... but if i do the same thing in some button click/link click events of something,,its failing and shows blank.

0
adarshsk
9/3/2008 4:28:45 PM

Nothing that we can do to help you there. I would set a trace on the variable and see when it is being changed.

NC...

 

0
NC01
9/3/2008 4:30:19 PM

Once again i would like to thank all of u.

 
The Source of Problem was in the add/save operations, for the immediate data reflection, i had used Response.Redirect("same page url"). So it was clearing the State of the label. 

So after changing the code such that i send the count as query string and setting it from the page load, the problem is Solved. 

0
adarshsk
9/3/2008 5:51:10 PM

Good for you!

NC...

 

0
NC01
9/4/2008 10:59:35 AM

Hi NC01,

your function contains window.onbeforeunload, just for my knowledge from where you calling this function to execute or how itz workin?.


SSN
Please remember to click "Mark as Answer" on the post that helps you.
0
suthish
9/4/2008 11:34:24 AM

The window.onbeforeunload function is part of the DOM and is called by it before the window.onunload event is fired. http://scriptasylum.com/tutorials/pageevents.html

NC...

0
NC01
9/4/2008 11:56:53 AM
Reply:

Similar Artilces:

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...

Get label value after seting from client side
I did with client side set the value of label to some string but whene i try to gete that string from label i get the old value. How can i get that value from server side that i did put from client side ...     Sorry for my bad english..Florim Maxhuni hey cann you post your code. bcoz even if the value of the label has been updated by client side, there shudn't be any difference, so might we can go thru your code and help youDiseirraMark it as an answer, if it helped you anyhow... U can always set and read from a label (span) using client side scripting, But ...

how to set get label control value in javascript.
How Can I get the label control let say Label1 text value in my javascript code.Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])Netprosys Inc.www.netprosys.comRemember to click "Mark as Answer" on the post that helps U Hi, you can use document.getElementById(id of the label).innerText;1 <%@ Page Language="C#" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <script runat="server"> 6 7 ...

How to set get label control value in javascript. #2
document.getElementByID("Label1") .innertext by this i can get label text by i want to get label value.can anyone help? Hi What do you actually mean by label value? asp:Label doesnt support any property called value . For eg if you declare a textBox something like this :- <asp:TextBox runat="server" ID="TextBox4" Text="Hii5"></asp:TextBox> then in borowser it is rendered as <input name="TextBox4" type="text" value="Hii5" id="TextBox4" /> so here you can see that you have value at...

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) .......

Iterating gridview control with javascript to get label values
I have a gridview control I need to iterate through to get some names from each row. Here is my HTML code as well as the names I need to get.<table cellspacing="0" cellpadding="2" rules="all" border="1" id="ctl00_ContentPlaceHolder1_gvAssistants" style="border-style:Solid;border-collapse:collapse;"> <tr style="background-color:DarkGray;"> <th scope="col"> </th><th scope="col">Assistants</th> </tr><tr style="white-space:nowrap;">...

Get label value on server side set by javascript
 HelloHow are all here.I have set the label text using javascriptdocument.getElementById("lblEmail").innerHTML = Login;Now when I try to get value (i.e. Text), by lblEmail.Text on ASP.Net server page, then the label shows no value or text. i.e. it is empty. why this is happening? how can I get value on Form set by Javascript?regards change in coding document.getElementById("lblEmail").value= "Hello World";   Please remember to click "Mark as Answer" on the post that helps you. This can be beneficial to other community members reading th...

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...

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...

cant get value of label controls changed by javascript for word bookmarks
I have a form that does a few calculations with javascript and puts the result in a label control.  But when I run my asp.net button click code and I try to get the value of that label to put it into a bookmark of a word document that it generates, but it wont get the value.  I can get the value of the label and write it to the screen but when I want to write it to the bookmark it only works if I change the label to a textbox.  Also, if I put a preset text value to the label control then it will write that value to the bookmark.  Im sure it will work if I ...

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 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...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in asp.net ( required field, range validator and others)..my question is the required field validator is a server side control. So does that mean that it does a post back?..is it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

How to get the Client side values in server side code.
Hi all, i have a proble i need to get the client side javascript values in C# code at server side. how can i pass those values? i am using version 1.1, i kno thatwe can use callback events mechnisam in 2.0 or ajax ,apart from that how we can pass? My problem is i need to stop the execution of the code based on after reciving values from the client   any ideas please???   Million thanks RamCheersRam MCP Hello Ram, a common approach is from javascript set an hidden field, then issue a postback. On the server-side, handle the post-back. Feel free to go deeper in your que...

Web resources about - how to get label control value in javascript. - 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/16/2016 5:28:52 PM