I have created one user control and need to convert that user control into custom control for the dll.
In that user control I need to use two javascripts also. Now could anyone help me to know how can I add that .js file reference into custom control code?
Usercontrol code:
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.MultiFile.pack.js" type="text/javascript"></script>
<div><%-- accept attribute can be used like accept="png|jpg"--%>
Multiple File Upload<br />
<asp:FileUpload ID="FileUpload10" runat="server" class="multi" accept="" />
<asp:Button ID="Button3" runat="server" Text="Submit" OnClick="jQueryUploadFiles" />
<br />
<asp:Label ID="lblMessage" runat="server" EnableViewState="false" ForeColor="Green" />
<br />
<asp:Label ID="lblError" runat="server" EnableViewState="false" ForeColor="Red" />
</div>
usercontrol.ascx.cs
private void FileUploadUsingJQuerySelectionMethod()
{
// check if file has been selected
HttpFileCollection files = Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
if (file.ContentLength > 0)
{
string path = ConfigurationManager.AppSettings["FilePath"];
string fileName = Path.GetFileName(file.FileName);
// now save the file to the disk
file.SaveAs(path + fileName);
lblMessage.Text += "File : <b>" + fileName + "</b> uploaded successfully !<br />";
}
}
}
If I understand your question correctly, you want to make sure that wherever you use this user control, the necessary JS-files get loaded too?
I’d suggest having a look at the ClientDependency Framework for this.
From the description of the project:
If you find this framework to be a bit overkill, you could always use the scriptmanager control to include your js file in the containing page.
An explanation on how to do this can be found here:
http://www.infinitezest.com/articles/embedding-javascript-files-in-your-custom-controls.aspx