CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 11/19/2007 7:09:45 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 17 Views: 80 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
18 Items, 1 Pages 1 |< << Go >> >|
nmeighty
Asp.Net User
Accessing label value using javascript and then manipulating that value11/19/2007 7:09:45 PM

0/0

Hi,

      I am having problem as follows.

      I am using Lable variable (asp:label) in a page which is having a master page.Label looks like as follows

<asp:Label ID="mylabel" runat="server"></asp:Label>

..... 

         In the code behind file I am assinging some value to the label as follows

      page_load()

{

mylabel.text=100.ToString();//this value comes at runtime

}

Now I want to access this value of label "mylabel" in the javascript and then i want to add some value (will be some interger of double value) and again display that value to the "mylabel".Please help me in how to do this?.suppose i want to get this functionality agains a button click event on client side.Waiting for the help................

Thanks,

nmeighty.

ysoldati
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/19/2007 7:32:29 PM

0/0

<button onclick="functioname()" .... />

<script type="text/javascript">
function functionname()
{

var label =  document.getElementById("mylabel");

label.text = ....;

}
</script>

 I think this will work, i m not sure if it is label.text or label.value to assign the value,

Hope this helps


Microsoft geek forever

-> Currently developing my blog...
Aeson07
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/19/2007 8:10:03 PM

0/0

As far as getting the value of your label into javascript, ysoldati is right, you can just use:

var labelValue = document.getElementById('mylabel.ClientID').value;

But if you want to send that value back to that server side control, you're going to have to save it to some control (the label may work, I'm not sure, if not you can use a hidden field) and then trigger a post back.  During the post back you can read the value of the label/hidden field and then update the label so the user can see the new value.

Hope that wasn't confusing, good luck. 

nmeighty
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/20/2007 1:05:05 PM

0/0

Hi,

     Thanks you very much for the reply.....and sorry for the late response...actually i was trying different things....Ahhh I forgot onething to mention that I want to get value from a label which is hidden i mean like below

<asp:Label ID="totalcharge" runat="server"></asp:Label> (we will assgn value to this label after some addition through javascript code) 

<asp:Label ID="mytotalhidden" runat="server" Visible="false"></asp:Label>(we will get value from this label to add something)

Now the problem is like when I use to access value from the mytotalhidden then i get java script error like 'object expected'.I am using following code to assign values to  the mytoalhidden and then i use to display them in the alert.here is the code

page_load()

{ 

this.totalcharge.Text = grandtotal.ToString("0.00");//comes at runtime can be some positive decimal value except null or 0

mytotalhidden.Text = grandtotal.ToString("0.00"); //comes at runtime can be some positive decimal value except null or 0

}

then in javascript code i am proceeding as follows

var txt = document.getElementById('<%=mytotalhidden.ClientID%>').innerHTML;

alert('value: '+txt);//to check what i am getting which is alway null

var temp=parseInt(txt);

txt=calculateTax(temp); //method to add some integer like 10 etc

alert(
'value: '+txt);

document.getElementById('<%=totalcharge.ClientID%>').innerHTML = txt;

 waiting for reply

Thanks,

nmeighty.

Aeson07
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/20/2007 1:18:47 PM

0/0

When you declare something as Visible="false" then there is no client-side HTML generated for that object, so your javascript will never be able to see it.  If you want a hidden field to store information in, then you should use a...well, a hidden field haha.  It looks like:

<input type="hidden" id="mytotalhidden" runat="server" />

Then you can access it in javascript using    document.getElementById('<%=mytotalhidden.ClientID%>').value; (you can access it in code-behind by using .value as well)

Also, as a side note, I don't think you need the "this" keyword in order to use your totalcharge control in page_load.

Hope this helps. 

nmeighty
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/21/2007 11:47:11 AM

0/0

Hi ,

         Thanks you so much for the reply.Yes I am able to achive the Functionality.I am marking your Reply as answer.........Please can any one guide me of the problem as below.

         In the same page I am also using a table to display some prices.I use to generate this table dynamically in the code behind of the aspx page.Here is the code which server sends to the client side

   <table width="95%" cellpadding="3" border="0" align="center">

        <tr>
       
            <td valign="top" class="TableBorder1">
           
                 <table id="ctl00_contentMain_priceTable" class="Table" border="0" style="width:100%;">
 <tr id="ctl00_contentMain_TableHeaderRow13">
  <th id="ctl00_contentMain_TableHeaderCell1" class="HeaderStyle33" colspan="6">Price Details</th>
 </tr><tr id="ctl00_contentMain_TableRow1">
  <td id="ctl00_contentMain_TableCell1"><span id="ctl00_contentMain_Labelins"><table id="mytable"  width="500px" bordercolor="black" ><tr><td><b>Description</b></td><td><b>Quantity</b></td><td><b>Unit Price</b></td><td><b>Extended Price</b></td></tr><tr><td width="200px">Adult Price</td><td>1</td><td>199.00</td><td><strong>&pound;199</strong></td></tr></br><tr><td width="200px">Price Adjustment</td><td>1</td><td>-35.00</td><td><strong>&pound;-35</strong></td></tr></br><tr><td width="200px">Other Charges</td><td></td><td></td><td><strong>&pound;86.90</strong></td></tr><tr><td></td><td></td><td></td><td><hr/></td></tr><tr><td width="200px">Total</td><td></td><td></td><td><strong>&pound;250.90</strong></td></tr></table></span></td>
 </tr>
</table>

you can see 250.90 in the third last line.this price also comes at runtime(Now the problem is how can i use some variable or something else to reference this value becuse it can be 344 ,300 etc) .Now I want to change it to the same value i will calculate using javascript value.i-e

In java script I will get the value from hidden input and then will proceed as follows

var txt = document.getElementById('<%=mytotalhidden.ClientID%>').innerHTML;

alert('value: '+txt);//to check what i am getting which is alway null

var temp=parseInt(txt);

txt=calculateTax(temp); //method to add some integer like 10 etc

alert(
'value: '+txt);

document.getElementById('<%=totalcharge.ClientID%>').innerHTML = txt;

now i want to get the position of 250.90 and replace with the value of txt variable .

Please help .....

Thanks,

nmeighty

 

 

 

 

Aeson07
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/21/2007 12:09:30 PM

0/0

I'm not sure if this is the best solution or not, but one idea that comes to mind is to store the price value that you want to be able to update in some variable or control, and then add that value into your table using <%=whatever%>

That way you could use javascript to update "whatever" to anything you need, and it will be placed back into the table on a post back. 

nmeighty
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/21/2007 12:32:47 PM

0/0

Hi,

    Thanks again.Is there any way to change the price of this span using javascript? you can see that the price is currently 250.90.I want to access this and then change the value after calculating ... 

<span id="ctl00_contentMain_Search_lblSearch"><br><b>Date: </b> 03 January, 2008<br><b>Total Price: </b> &pound;250.90<br></span>

Thanks,

nmeighty.

iliemail
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/21/2007 1:31:48 PM

0/0

 put the price in a label. give it an id and you should be able to acces it from js.

something like 

<span id="ctl00_contentMain_Search_lblSearch">

    <br>

     <b>Date: </b> 03 January, 2008

     <br>

     <b>Total Price: </b> &pound;

    <label id="myLabel" value="250.90"/><br>

</span>


i think you example is too complicated 

nmeighty
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/21/2007 3:09:20 PM

0/0

Hi,

      Yes you are very much right in saying the example is too much complex.Now I will try to make the scenerio more clear.I needed to generate a table at runtime in the code behind of some file say "myfile.aspx".Now i use to generate the table as follows

I used a label with ID "lab" and then in that label i used to do as follows

lab.Text="<table id=\"mytable\" width=\"500px\" bordercolor=\"black\" ><tr><td><b>Description</b></td><td><b>Quantity</b></td><td><b>Unit Price</b></td><td><b>Extended Price</b></td></tr>";

foreach (Pricedetail d in detaillist.price) //detailist is a list of Pricedetail type objects ,it can contan any number of prices .

{

grandtotal += d.ExtendedCost;

othercharges += d.ExtendedCost;

grandtotal += d.ExtendedCost;

lab.Text += "<tr>";

lab.Text += "<td width=\"200px\">" + CommonFunctions.ToTitleCase(d.Description) + "</td><td>" + d.Quantity + "</td><td>" + d.UnitCost.ToString("0.00") + "</td>" + "<td><strong>&pound;" + d.ExtendedCost;

lab.Text += "</strong>" + "</td></tr></br>";

grandtotal += d.ExtendedCost;

}

}

othercharges += bookingCharges;

if (othercharges>0)

{

lab.Text = lab.Text +
"<tr>";

lab.Text += "<td width=\"200px\">" + "Other Charges" + "</td><td></td><td></td>" + "<td><strong>&pound;" + othercharges.ToString("0.00");

lab.Text += "</strong></td></tr>";

}

grandtotal += 10;

lab.Text +=
"<tr><td></td><td></td><td></td><td><hr/></td></tr>";

lab.Text = lab.Text + "<tr>";

lab.Text += "<td width=\"200px\">" + "Total" + "</td><td></td><td></td>" + "<td><strong>&pound;" + grandtotal.ToString("0.00");//this is the line where i need to insert label .Now how can i do that?? lab.Text += "</strong></td></tr>";

lab.Text += "</table>";

Now this is the line where i need to insert label .Now how can i do that??third last line of the code

lab.Text += "<td width=\"200px\">" + "Total" + "</td><td></td><td></td>" + "<td><strong>&pound;" + grandtotal.ToString("0.00");//

Thanks,

nmeighty.

Aeson07
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/21/2007 3:21:50 PM

0/0

To insert your label/field/whatever into your line you would just use:

lab.Text += "<td width=\"200px\">" + "Total" + "</td><td></td><td></td>" + "<td><strong>&pound;" + myhiddentotal.value;

or replace myhiddentotal.value with whatever control you may be using (myTotalLabel.Text, etc)

Hope this helps. 

nmeighty
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/21/2007 5:51:30 PM

0/0

Hi,

      It will not solve the problem,because it will only insert the value at the position below

lab.Text += "<td width=\"200px\">" + "Total" + "</td><td></td><td></td>" + "<td><strong>&pound;" + myhiddentotal.value;

    .However I want to change that value using javascript .However i have tried to use as below

lab.Text += "<td width=\"200px\">" + "Total" + "</td><td></td><td></td>" + "<td><strong>&pound;<asp:Label runat=\"server\" Value="+grandtotal.Tostring("0.00")+" ID=\"Totalamount\" ></asp:Label>";

but its also not working..

Thanks,

nmeighty.

Aeson07
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/21/2007 6:27:14 PM

0/0

All of this code is executed in the code-behind (I.E. during a postback) the only time lab.Text is going to be updated with your new values is when you post back to the server via something like a button click.  Theres a way to call a post back from javascript too, but I'm not very familiar with the code, just do a search for __dopostback or javascript post back and you should find plenty of threads on the forum about it.

nmeighty
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/21/2007 7:09:07 PM

0/0

Hi,

     Yes I think I need to learn some more javascript and also will need to change the coding.Thanks you very much for all the help you have done so far.Thanks to all

Thanks,

nmeighty.

iliemail
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/21/2007 7:52:11 PM

0/0

 

Why is important to use javascript? can'y you use a grid view?
nmeighty
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/22/2007 11:29:02 AM

0/0

Hi,

     I have to use javascript its the requirement...no worries..

Thanks,

nmeighty

nmeighty
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/22/2007 11:29:58 AM

0/0

Hi,

     I have to use javascript its the requirement...no worries..and i cant use gridview in the current scenerio.I have used some label and span variables and hopefully i will be able to get the desired results.

Thanks,

nmeighty

nmeighty
Asp.Net User
Re: Accessing label value using javascript and then manipulating that value11/22/2007 12:11:13 PM

0/0

Hi,

    Okay lets hava a scenerio that we hava list of prices at runtime from database.there can be any number of prices may be 2,3,4,5,and so on...> Now we we need to display them at run time in a good format.Now I got the logic to generate a table at runtime in the codebehind file of mypage.aspx.So i did the above thing.Also the same total is represendted at 3 different locations of the page. One in the dynamically generated table,second in some usercontrol and the third one is a simple label.Now I have a button.When user clicks on that button then i need to change values at all the 3 locations.....

Thanks,

nmeighty.

18 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Professional JavaScript for Web Developers Authors: Nicholas C. Zakas, Pages: 646, Published: 2005
JavaScript Bible Authors: Danny Goodman, Michael Morrison, Brendan Eich, Pages: 1173, Published: 2007
Head First JavaScript Authors: Michael Morrison, Pages: 615, Published: 2007
Programming ASP.NET AJAX Authors: Christian Wenz, Pages: 454, Published: 2007
JavaScript: The Complete Reference Authors: Thomas A. Powell, Fritz Schneider, Pages: 948, Published: 2004
Creating Applications with Mozilla Authors: David Boswell, Ian Oeschger, Eric Murphy, Pages: 454, Published: 2002
Essential XUL Programming: The How to Guide for Web Developers and Programmers Authors: Vaughn Bullard, Kevin T. Smith, Michael C. Daconta, Pages: 418, Published: 2001
HTML & XHTML: The Definitive Guide: The Definitive Guide Authors: Chuck Musciano, Bill Kennedy, Pages: 678, Published: 2006
AJAX, Rich Internet Applications, and Web Development for Programmers Authors: Paul J. Deitel, Harvey M. Deitel, Pages: 991, Published: 2008
Programming Web Services with Perl Authors: Randy J. Ray, Pavel Kulchenko, Pages: 470, Published: 2003

Web:
Accessing label value using javascript and then manipulating that ... Now I want to access this value of label "mylabel" in the javascript and then i want to add some value (will be some interger of double ...
Manipulating radio and check boxes in JavaScript - ajax,css,js ... checked, Contains a boolean value indicating whether a box is selected or not. ... Now that we know how to access and manipulate a single box, lets expand our workarea to ... S-Label-Fields="TRUE" --><--webbot bot="SaveResults" endspan --> .... 上一篇文章:Enabling/ disabling form elements using JavaScript | 下一篇 ...
Planet PDF - Using Colors in Acrobat JavaScript Kas offers a crash course in manipulating color in PDF files. ... Subsequent positions in the array designate color-channel values (which can ... To access the green channel of the darkRed color, you'd inspect or set darkRed[2]. ... new text field (using Acrobat's Form tool) and name it 'swatch', then create a push ...
Manipulating data in Domino Web Access The formula is compiled and then executed. In addition, Domino Web Access ... Traditional Domino Web applications define a field using Domino Designer and at the ... In Domino Web Access, however, all the item (field) values for a document ... JavaScript variables are case-sensitive and Domino item names are not, ...
Using Dojo with the Zero Resource Model In fact, this is exactly how the above Dojo dijits access data represented by Dojo Data implementations. .... var birthDateLabel = metadata.birth_date.label; .... You can create and manipulate resources using zero.grid.DataGrid 's attributes. The following JavaScript example shows how to set the value of a selected ...
Traversing and Manipulating the MT::Template DOM | MovableType.org ... Let's take some sample template code, and then see how Movable Type sees it in ... Additional DOM API methods exist in accordance with the conventions of Javascript's DOM APIs. Now, once you have access to the node you want to make changes to, ... The following code does this by extracting the current value of the ...
Manipulating Cookies in Flash via ASP Sep 8, 2000 ... If cookies are not accepted, Flash jumps to the label ... Then ' Session variable contains value ' Thus browser accepts ... This means that the browser accepts cookies when the value in the session variable is still present after a redirect. ... In ASP, cookies can be set easily using the Response. ...
Design Science MathFlow Premium Support Jun 8, 2007 ... However, it is possible to use JavaScript to interact with the InputControl, ... NET textbox we can then manipulate it however we choose. .... NET code can access it. The field is made invisible by placing it inside a DIV and setting it's ... the value using .NET and do whatever we want with it. ...
Adding Behavior to Bindings Using Wrox Article : Manipulating ASP.NET Pages and Server Controls with ... For example, look at a simple Label server control, shown in Listing 1, ... Listing 2: Using JavaScript to show the current time for the end user ... GetType() , the key, the script to include, and then a Boolean value setting of True so that . .... and Devin Rader include Connecting to Oracle or Access from ASP. ...

Videos:
Developing JavaScript with Chickenfoot Google TechTalks July 25, 2006 Rob Miller Michael Bolin ABSTRACT Chickenfoot is a Firefox extension that embeds a JavaScript programming ...




Search This Site:










menu with security

different colours in navigation menu

help with using the mainmenu class

dynamically override sitemapnode?

sqlcachedependency doesn’t refresh my treeview immediately

master page command information?

change image in treeview node when it expands

asp.net themes discussion

menu control, add child to parent

menuitem and imageurl problem

looking for treeview property

treeview: how do i display only a part of the site?

web design templates

changing text size mixed the browser views of the content page and master page?

site map error

navigation menu not avalable from other folder

how can i hide top menu and filter submenu?

wizard inside a contentplaceholder inside a master page

parser error message: could not load type '_prodwhite'.

.htm docs and “contentplaceholder”

best way to completely change a whole site....

treeview as directory/filebrowser

change site map provider at runtime

how do i disabled back button in ie for master.page, those who have content pages

how to display certain levels in a treeview menu?

how to limit menu from pages in sitemap

dynamicaly setting the hyperlink property of menuitem

need to make a call to master page function from inside of a dynamically loaded user control

applying css in vwd2008

master pages +forms

  Privacy | Contact Us
All Times Are GMT