-
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
-
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.
-
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>
-
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?
-
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>
-
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.