Can not find control on Content page

2 posts, 1 answers
  1. Lubna Ansari
    Lubna Ansari avatar
    65 posts
    Member since:
    Feb 2010

    Posted 11 Mar 2010 Link to this post

    Hi,

    My program was working fine until I create a Master content page. I need to set values of some controls on a content page load using javascript and I am not able to find the controls on the content page. I am using a external .js file for the javascript funtion. Following is my Master Page code.

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
    <!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>
        <title>Untitled Page</title>
         <link rel="Stylesheet" type="text/css" href="StyleSheet/calendar-blue.css" />
        <link rel="Stylesheet" type="text/css" href="StyleSheet/template.css" />
        <script type="text/javascript" src="JS/JScript.js"></script>
        <asp:ContentPlaceHolder id="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="divMasterPageContent">
       
       <!-- START Page Body -->
       <table id="tblCenterContent">
        <tr valign="top" height="100%">
         <!-- START Page Body - Left Panel -->
         <td>
             <asp:ContentPlaceHolder id="cntContent" runat="server">        
              </asp:ContentPlaceHolder>
         </td>
         <!-- END Page Body - Right Panel -->
        </tr>    
       </table>
       <!-- END Page Body -->   
      </div>   
        </form>
    </body>
    </html>

    Below is my Content page code.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="_Default1"
        MasterPageFile="~/MasterPage/MasterPage.master" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <asp:Content runat="server" ID="Default2" ContentPlaceHolderID="cntContent">
    <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="LoadingPanel1">
                <div style="float: left; width: 500px">
        <asp:TextBox ID="txtTest" runat="server" Text="abc"></asp:TextBox>
    </div>
    </telerik:RadAjaxPanel>
    </asp:Content>

    My Js code is

     

    function

     

    getTextValuevalue()

     

    {

     

    if(document.getElementById('<%=TransID.ClientID%>')!=null)

     

    {
    }

    }

    It is returning me null value.

     

     

  2. Answer
    T. Tsonev
    Admin
    T. Tsonev avatar
    2788 posts

    Posted 15 Mar 2010 Link to this post

    Hi Lubna,

    The server script block (<%=TransID.ClientID%>) will only work as part of the aspx page. In order to use an external file you need to pass the id as a parameter and resolve it on the page:

    In aspx:

    myFunction("<%=TransID.ClientID%>");

    In js:

    myFunction(clientId)
    {
    }

    I hope this helps.

    Kind regards,
    Tsvetomir Tsonev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top