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

Setting a css in Usercontrol from parent page

1 Answer 263 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nambi
Top achievements
Rank 1
Nambi asked on 13 Sep 2011, 04:36 PM
Hi,
Am able to access the text box in the user control in the parent page.But when i try to change its css am getting "

Object doesn't support this property or method"


Error occurs in:
tb.get_styles().EnabledStyle[1] += " red_bgd";

what i tried:
var tb = document.getElementById(auditId);  or
var tb = $find(auditId);
I tried To get the control using $find() but it returns nulll. so i cant set style.




<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
 

    
                <script type="text/javascript" language="javascript">

            function AssignValue() {
            var auditId=GetClientId('AuditUC1_tbAudit');
            var tb = document.getElementById(auditId);
           tb.get_styles().EnabledStyle[1] += " red_bgd";
           tb.updateCssClass();
            return false;
            }    
            
            function GetClientId(strid)
{
     var count=document.forms [ 0 ] . length ;
     var i = 0 ;
     var eleName;
     for (i = 0 ;  i < count ;  i++ )
     {
       eleName = document.forms [ 0 ] . elements [ i ] .id;
       pos=eleName.indexOf ( strid ) ;
       if(pos >= 0)  break;          
     }
    return eleName;
 }     
            
     
 
    }
    </script>
    </telerik:RadScriptBlock>
        <style type="text/css">
    .red_bgd{
    background-color:#F8E5E5;
   color:#A90000;    
}   
    </style>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Name:<telerik:radtextbox ID="tbName" Runat="server"  
            EnableEmbeddedSkins="false">
        </telerik:radtextbox></div>
    <p>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    </p>
    <p>
        <uc1:AuditUC ID="AuditUC1" runat="server" />
    </p>
    <p>
        &nbsp;</p>
    <p>
        &nbsp;</p>
    <p>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click"  OnClientClick="AssignValue();"/>
    </p>
    </form>
</body>
</html>


---------------User control----------------------
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AuditUC.ascx.cs" Inherits="BasicTelerik.AuditUC" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

Audit Desc:
 <telerik:RadTextBox ID="tbAudit" Runat="server"  EnableEmbeddedSkins="false">
        </telerik:RadTextBox>
        <br />
        <br />

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 16 Sep 2011, 08:46 AM
Hello Nambi,

The UserControl is a naming container, so your textbox is not directly accessible on the page. You could try using the FindControl() method inside the code block used inside $find.
$find('<%=AuditUC1.FindControl("tbAudit").ClientID%>')


All the best,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
Tags
General Discussions
Asked by
Nambi
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or