I formerly asked for a Best-Practice regarding this,
But this is one the strategies
Here is the situation we’ll go:
-
we want to first add JQuery to the Page (as an example via the
Web Resources ) -
after that load a library
-
The Library is using a template named :
"Hello sticky hide" -
Add the Library-User Code Ready Blah blah blah
I want to complete this practice at least for my own.
Maybe It simply be fixed just by adding line, removing a char or changing place
but any idea and hopefully the fix is appreciated
It doesn’t show any error but there is no result.
[assembly: WebResource("Quad.WebControls.JQuery.js", "application/x-javascript")]
[assembly: WebResource("Quad.WebControls.ProHello.js", "application/x-javascript")]
namespace Quad.WebControls
{
[ToolboxData("<{0}:QuadBar runat=server></{0}:QuadBar>")]
public class QuadBar : WebControl
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (!DesignMode)
{
//ClientScriptManager cs ;
ScriptManager sm= ScriptManager.GetCurrent(Page);
if (sm == null)
throw new HttpException("Error");
string scriptJQuery = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Quad.WebControls.JQuery.js");
string scriptjqHello = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Quad.WebControls.ProHello.js");
HtmlGenericControl jq = new HtmlGenericControl("script");
...
HtmlGenericControl jqHello = new HtmlGenericControl("script");
...
Page.Header.Controls.Add(jq);
Page.Header.Controls.Add(jqHello);
//-------
**RenderControl**
public override void RenderControl(HtmlTextWriter writer)
{
base.RenderControl(writer);
//StringBuilder sbInit = new StringBuilder();
StringBuilder sb = new StringBuilder();
sb.Append(" <script type=\"text/javascript\"> ")
.Append(" Sys.WebForms.PageRequestManager.getInstance().add_endrequest(EndRequestHandler); ")
.Append("$(document).ready(function () {")
...
.Append("});")
.Append("</script>");
writer.Write(sb.ToString());
}
The Aspx Part – (The Control is registered )
Form – Placed inside the Asp.Net Form
<asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
<div class="Hello sticky hide">
<p>
MHM Message</p>
<a class="close" href="javascript:">
<img src="images/icon-close.png" /></a>
</div>
<Quad:QuadBar runat="server" ID="proHello" />
<div class="wrapper">
<ul>
<li><a href="#" class="round green button" id="sticky"><span>Sticky bar</span></a> will
remain visible even user scroll the page.</li>
</ul>
</div>
The answer could be found here :
Making a DLL of a User Control plus Jquery embeded in
although it could be counted as a duplicate of one of my questions