javascriptasp.netcomposite-controlsasp.net-customcontrol

Using javascript in ASP.NET Composite control


I have a custom asp.net server control to display images.What I need now is to draw a rectangle on the center of image and the rectangle should be re sizable by dragging on its edges.Is it possible to accomplish this using JavaScript ?. I need to embed that script in that control. Is it possible ?


Solution

  • You can include a javascript file in a server control.

    Add a reference to the assemblyinfo.cs

    [assembly: WebResource("Custom.js", "text/javascript")]
    

    Then a reference on the PreRender:

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        string resourceName = "Custom.js";
    
        ClientScriptManager cs = this.Page.ClientScript;
        cs.RegisterClientScriptResource(typeof(CustomControls.Custom), resourceName);
    }
    

    Here is a nice article on the subject