This is a migrated thread and some comments may be shown as answers.

using <%= %> as HTML element attribute

6 Answers 116 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Gabriel
Top achievements
Rank 2
Gabriel asked on 16 Oct 2012, 04:30 PM
Hello everyone,

I'm trying to use Server snippets incrusted in HTML with no luck. The code is as follows:

<label for="<%= myTextBox.ClientID %>" >Text</label>
<asp:TextBox id="myTextBox" runat="server />

The server throws me the following exception:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

I know I have to use RadScriptBlock if I want to use it in javascript, but how can I achieve this behavior with Telerik?
I also know that Telerik:RadTextBox contains a label option, but I need it this way because I'm using a CSS template.

in advance, thanks

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Oct 2012, 05:15 AM
Hi Gabriel,

I suppose you want to set CSS for label in the RadTextBox. You can override the default Css as shown below.

ASPX:
<telerik:RadTextBox ID="myTextBox" runat="server" Label="Your Label">
</telerik:RadTextBox>

CSS:
<style type="text/css">
 .RadInput_Default .riLabel
  {
    color:Red !important; //Your style
  }
</style>

Please elaborate your scenario if it doesn't helps.

Regards,
Princy.
0
Gabriel
Top achievements
Rank 2
answered on 17 Oct 2012, 01:18 PM
Hello Princy, thank you for the reply.

I don't want to override the CSS.

Look, the problem is I have to create the following structure for my form elements:

<div class="control-group">
    <label for="<%= myTextBox.ClientID %>" class="control-label">LabelText</label>
    <div class="controls">
        <asp:TextBox ID="myTextBox" runat="server" CssClass="input-square">
    </div>
</div>

I can't create this structure with Telerik:RadTextBox, can I?

I think one solution might be to create an user-control, but I don't really understand why Telerik limits so much this incredible feature of asp.
0
Princy
Top achievements
Rank 2
answered on 18 Oct 2012, 04:35 AM
Hi,

Unfortunately I cannot replicate the issue at my end. I was able to show a label with RadTextBox. Attached is the screenshot.
aspx:
<div class="control-group">
    <label for="<%= myTextBox.ClientID %>" class="control-label">LabelText</label>
    <div class="controls">
        <telerik:RadTextBox ID="myTextBox" runat="server" CssClass="input-square"></telerik:RadTextBox>
    </div>
</div>

Regards,

Princy.
0
Gabriel
Top achievements
Rank 2
answered on 18 Oct 2012, 06:00 PM
Nice, now add a RadScriptManager and a RadAjaxManager to the page and see how it behaves.

Thanks.
0
Accepted
Vasil
Telerik team
answered on 19 Oct 2012, 07:20 AM
Hello Gabriel,

I would like to refer back to your original post. You could use
<asp:Label runat="server" AssociatedControlID="myTextBox" />

This will work even if the myTextBox is RadTextBox, if you are using versions after Q1 2012

Kind regards,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Gabriel
Top achievements
Rank 2
answered on 19 Oct 2012, 02:18 PM
OMG!!

This is the first time I see AssociatedControlID property!!!! I didn't know it existed!!!

thank you Vasil.

PS: That sound really noob, I know xD
Tags
Ajax
Asked by
Gabriel
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Gabriel
Top achievements
Rank 2
Vasil
Telerik team
Share this question
or