0

I only have access to the .ascx file and not codebehind.

I want to be able to display only the left portion of a string returned by a <asp:label control.

I've thought about styling the label as display:none; and addind a second <asp:label and setting the text property from the hidden control with some javascript manipulation but I can't work out how?

Any ideas?

Crab Bucket
  • 6,219
  • 8
  • 38
  • 73
MRH
  • 11
  • 2

2 Answers2

0

you can do this on the client side with javascript easily.

if a char ie '-' delimits the sections, you can gt the value with javascript and .split it by '-'

check this out for examples SO JS Split question

Community
  • 1
  • 1
atmd
  • 7,430
  • 2
  • 33
  • 64
0

If you are comfortable using jQuery, try this:

$(function(){
 var text = $("LABELID").html();
 var Index = 0;
 var Length = text.indexOf("-") + 1;
 var text = $("LABELID").html().substring(Index, Length);
  $("LABELID").html(text );
});

OR

$(function(){
     var text = $("LABELID").html().split("-")[0];
      $("LABELID").html(text );
    });
Kapil Khandelwal
  • 15,958
  • 2
  • 45
  • 52
  • Wouldn't using `.text()` be a better choice than `.html()`? Less chance of grabbing a partial html tag. – pete Jun 22 '12 at 11:06