<asp:label runat="server" text="MyValue" ID="MyLabel"></asp:Label>
//At the end of the page
<script type="text/javascript">
var labelText = document.getElementByID("<%=MyLabel.ClientID%>").innerHTML;
//Perform substring operations
//...
//Finally update the value!
document.getElementByID("<%=MyLabel.ClientID%>").innerHTML = "Your value";
</script>
using System.Web.Compilation;
[ExpressionPrefix("Code")]
public class CodeExpressionBuilder : ExpressionBuilder
{
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry,
object parsedData, ExpressionBuilderContext context)
{
return new CodeSnippetExpression(entry.Expression);
}
}
baodt
Member
130 Points
165 Posts
Please help using script in asp:label
May 31, 2012 09:21 AM|LINK
i want using script in label to substring its value.
Example : <asp:label runat="server" text="substring(value)"
function substring(){}
How can i do ???
RameshRajend...
Star
7983 Points
2099 Posts
Re: Please help using script in asp:label
May 31, 2012 09:33 AM|LINK
Hi,
Please try this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="TestApplication.WebForm3" %> <!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 runat="server"> <title></title> <script type="text/javascript"> function hello() { alert('Hi, good morning!'); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="lblMsg" onclick="javascript:hello();" Text="Click Here" Font-Bold="true" runat="server"></asp:Label> </div> </form> </body> </html>Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: Please help using script in asp:label
May 31, 2012 09:37 AM|LINK
we cant do like this
this has be assigned from codebehind, set the id to label and assign it from code behind
if you wan to do it using javascript when at the end of the document get the client id and assign the text
roopeshreddy
All-Star
20155 Points
3328 Posts
Re: Please help using script in asp:label
May 31, 2012 09:38 AM|LINK
Hi,
You can do like this!
<asp:label runat="server" text="MyValue" ID="MyLabel"></asp:Label> //At the end of the page <script type="text/javascript"> var labelText = document.getElementByID("<%=MyLabel.ClientID%>").innerHTML; //Perform substring operations //... //Finally update the value! document.getElementByID("<%=MyLabel.ClientID%>").innerHTML = "Your value"; </script>Hope it helps u...
Roopesh Reddy C
Roopesh's Space
karthicks
All-Star
31382 Points
5424 Posts
Re: Please help using script in asp:label
May 31, 2012 09:39 AM|LINK
hi, your Req. is not clear. anyhow here are some examples
<script> function CutName() { var label = document.getElementById('<%= Label3.ClientID %>'); label.innerText = label.innerText.substring(0, 8); } </script> </head> <body onload="CutName()"> <form id="form1" runat="server"> <asp:Label ID="Label1" runat="server" Text='<%# Name.Substring(0, 8) %>'></asp:Label> <span> <%= Name.Substring(0, 8) %></span> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <asp:Label ID="Label3" runat="server" Text="karthick sundaram"></asp:Label> </form> </body> public String Name { get; set; } protected void Page_Load(object sender, EventArgs e) { Name = "karthick sundaram"; this.Label1.DataBind(); this.Label2.Text = Name.Substring(0, 8); }Karthick S
Ramesh T
Contributor
5131 Points
827 Posts
Re: Please help using script in asp:label
May 31, 2012 10:00 AM|LINK
Its a bit complex one, u could use Expression Builders. Below link may help u
http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx
U have to do the following
1) Add the following class
using System.Web.Compilation; [ExpressionPrefix("Code")] public class CodeExpressionBuilder : ExpressionBuilder { public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { return new CodeSnippetExpression(entry.Expression); } }2) Add the following setting in ur web config
<system.web> <compilation debug="true" targetFramework="4.0" > <expressionBuilders> <add expressionPrefix="Code" type="Namespace.CodeExpressionBuilder"/> </expressionBuilders> </compilation>3) And alter ur label in markup as below
I reckon 'value' is defined in ur code behind as below
public partial class WebForm1 : System.Web.UI.Page { public string value { get; set; }baodt
Member
130 Points
165 Posts
Re: Please help using script in asp:label
May 31, 2012 10:29 AM|LINK
I am really thank you very much.
I ask question because i am having a problem. When data is long, td is break. I want if it is so long, it will ....
In css it is text-overflow: ellipsis;.
But if i use it, i must use property table-layout: fixed;.
And my problem is data layout will override other td when change solution or change size browser.
Any one can give me solution . Thank you very much again.