Results 1 to 6 of 6

Thread: ASP.net Control help

  1. #1

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    ASP.net Control help

    Hey there.
    right im having an issue that i cant figure out why it does not work.

    i have a web project, called "Common", which contains server controls and other common items i will use in my other web projects in the solution.

    in this project i have a class which renders javascript files to be added to the webpage. so it is basically a class, "JavaScriptInjectionControl", that inherits from System.Web.UI.Control.

    Now in my other project in my solution i add a reference to the library (dll) produced by my Common project.
    Now here i have a UserControl in which i want to add the JavaScriptInjectionControl to my servercontrol.
    To do this i modify the web.config file to add the assembly
    <add assembly="Common" namespace="Common" tagPrefix="adfc"/>

    Now i go back to my UserControl and in the design mode i can see <adfc:JavaScriptInjectionControl> in the intellisense.

    Everything looks great.

    so i add <adfc:JavaScriptInjectionControl id="jsic1" runat="server"></adfc:JavaScriptInjectionControl>

    My problem is that when my user control runs it does not implement this JavaScriptIngectionControl and i have no idea why.

    Everything seems fine, i get no compile or runtime errors, my webpage just doesnt seem to render it.

    (If i add a usercontrol into my project that implements the server control from the common project add this to my webpage it works!!!!)

    Thanks for any help
    Last edited by Strider; Sep 8th, 2008 at 10:53 PM.
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: ASP.net Control help

    You haven't shown any code, so there's no way for me to know what is causing the problem.

  3. #3

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: ASP.net Control help

    Common Project - Server Control
    Code:
    public class JavascriptInjectionServerControl : System.Web.UI.Control
        {
            #region _Private Members_
            private string _scriptName = string.Empty;
            private bool _includeStartTag = true;
            private bool _includeEndTag = true;
            #endregion
    
            #region _Constants_
            private const string startTag = "<script language=\"javascript\" type=\"text/javascript\">\n";
            private const string endTag = "\n</script>";
            #endregion
    
            #region _Public Properties_
            public bool IncludeStartTag
            {
                get { return _includeStartTag; }
                set { _includeStartTag = value; }
            }
    
            public bool IncludeEndTag
            {
                get { return _includeEndTag; }
                set { _includeEndTag = value; }
            }
    
            public string ScriptName
            {
                get { return _scriptName; }
                set { _scriptName = value; }
            }       
            #endregion
    
            #region _Protected Methods_
            protected void RenderControl(HtmlTextWriter writer, System.Reflection.Assembly callingAssembly)
            {
                string script = ReplaceTokens(ResourceHelper.GetJavascript(_scriptName, callingAssembly));
                writer.Write(String.Format("\n{0}{1}{2}", _includeStartTag ? startTag : string.Empty, script, _includeEndTag ? endTag : string.Empty));
            }
            #endregion
    
    
        }

    User Control Web Project web config
    Code:
    <pages>
    			<controls>
    				<add assembly="Common" namespace="Common" tagPrefix="adfc"/>
    			</controls>
    		</pages>
    User Control page
    Code:
    <adfc:JavascriptInjectionServerControl ID="JavascriptInjectionServerControl3" runat="server" ScriptName="HealthManagementScript" IncludeStartTag="true" IncludeEndTag="true"></adfc:JavascriptInjectionServerControl>
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: ASP.net Control help

    Alright, it all seems fine and should work. What happens when you hardcode the script tag or anything else, such as <a href="http://www.mendhak.com/">blah</a> in there?

  5. #5

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: ASP.net Control help

    all other web control work fine on the page. and any other server controls i have work ok, its only the one above that when the page loads it doesnt render it....
    for example when i use the jis server control below which is a class inside my project which inherits from the server control in the common project it works!! its very frustrating...
    <pages>
    <controls>
    <add assembly="HealthManagement.Note" namespace="Note" tagPrefix="jis"/>
    <add assembly="Common" namespace="Common" tagPrefix="adfc"/>
    </controls>
    </pages>
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: ASP.net Control help

    Then try, from the control's codebehind, ClientScript.RegisterClientScriptInclude. In order to 'get' the ClientScript, you will probably need to use an HttpContext.Current.Request.Page, but you will need to investigate via intellisense.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width