Including Javascript with a custom control in an ASP.Net website -


I have a custom date control that is essentially a text box and ajaxToolKit calendar extender. I want to include javascript in control and it has to work properly, even if any page is on control. Control is called DateControl.ascx

So I have two JavaScript functions, dateEditor_OnShown and dateEditor_OnHiding. They are bound to load the DateControl.ascx page ...

  Calendar Extender.OnClientShown = "dateEditor_OnShown"; Calendar accredited .onlineheading = "date editor-onhiding";  

A datacontrol device is used on two separate pages. If I put Javascript directly into the HTML of the Continental, it will only work on the default page, but it will crash when I load the next page with control. Error is a JS runtime error 'dateEditor_OnHiding' is undefined.

If I try to link the JavaScript file from my DateControl's html ...

  & lt; Script type = "text / javascript" src = "../ javascript / IE6 calculatorExtenderFix.js" & gt; & Lt; / Script & gt; Instead of being directly javascript in the page, it immediately crashes with the same error. I should keep in mind that the path of JS is correct.  

The only way I can actually do this is to work if I link to Javascript on every page which is used to control.

Update: I feel the need to understand a bit. The suggested solutions are highly appreciated, but either I do not understand or they In my case for whatever reason (probably possibly pre) will not work.

So, how it looks like my control basically ..

   & Lt; / Div & gt; & Lt; / Div & gt;  

In the aspx page, with that exact code, if I place exact JavaScript in script tags then the page looks like this ...

  Lt; Script type = "text / javascript" & gt; Function Debt Editor / Account Control (Open Control), {...} Function Debt Editor / OnHeading (Date Control, Blank Ententor) {...} & lt; / Script & gt; & Lt; Div id = "CustomDateControl" style = "& lt;% # ControlStyle%>" & Gt; & Lt; Div id = "textbox" style = "display: inline, white space: aboper;" & Gt; & Lt; ASP: Textbox Runat = "Server" id = "TextText Calendar" Style = "& lt;% # Text Box Style% & gt;" / & Gt; & Lt; / Div & gt; & Lt; Div id = "calendar" run = "server" & gt; & Lt; AjaxToolkit: Calendar adder runat = "server" id = "calendarexender" format = "mm / dd / yyy" targetcontrol id = "textileender" popupbutton id = "calendar image" /> & Lt; / Div & gt; & Lt; / Div & gt; "DateEditor_OnHiding" is undefined when it still crashes when reaching control in the second page (not the default page that is not before). Now, if I link to a JS file, I get the same code using a relative path as suggested below.  

In addition, if suggested below, then I override on the operator and include the register client script, I get the same result once again. Control always works on the default page, but never on the second page, although I can tell that the script is included in the control.

Any thoughts?

Attach the following code to your user control.

  Protected Override Zero OnPreRender (EventArgs e) {Page.ClientScript RegisterClientScriptInclude ("DateControl", this. ResolveClientUrl ("~ / JavaScript / IE6CalendarExtenderFix.js")); Base.OnPreRender (E); }  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -