3 Replies - 7798 Views - Last Post: 26 August 2010 - 07:25 AM Rate Topic: -----

#1 ariebsomer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 12-August 10

Calling JavaScript in class file

Posted 25 August 2010 - 01:24 PM

I am porting a project from classic ASP to ASP.NET.

This application is an intranet site that connects with our application database to dynamically display data in various formats on the site.

Several pages of the site have a filterbar and toolbar on them that allows for things like print screen, export to Excel, add to favorites, and a kind of GUI interface to allow for the creation of some SQL filtering.

So originally, there was an ASP file called toolbar that never really got displayed, it was just an asp file that was included in whichever pages needed to display the toolbar.

However, now with this being ASP.NET, there are no more includes statements, and since this isn't really a 'page' so much as a collection of subs and functions, I just made it a class file to be referenced as needed by the pages that have a toolbar.

But the toolbar buttons are all javascript-driven. So I have a toolbar.js file with all of the javascript functions needed by toolbar.vb, but for some reason they aren't working. Each sub in the toolbar.vb class file has this if statement:

'javascript file call
            If (Not ClientScript.IsStartupScriptRegistered("javascript")) Then
                ClientScript.RegisterStartupScript(Me.[GetType](), "MyScript", "<script language=javascript src='toolbar.js'></script>")
            End If


I figured this should detect if the RegisterStartupScript had been initialized already or not and if not, initialize it.

The only thing I can figure is that since the class file sites in the App_Code folder, the js may not be getting accessed. On all of my regular pages, I couldn't access any javascript in a subfolder (no matter what pathway syntax I tried) and had to put the .js files in the root directory.

Anyone?

Is This A Good Question/Topic? 0
  • +

Replies To: Calling JavaScript in class file

#2 ans2007kumar   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 25-September 09

Re: Calling JavaScript in class file

Posted 26 August 2010 - 12:42 AM

Response.Write("<script> alert('Some data found to be missing in the file');</script>");

this is how you use javascript and even all funcutions.
Was This Post Helpful? 0
  • +
  • -

#3 ariebsomer   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 12-August 10

Re: Calling JavaScript in class file

Posted 26 August 2010 - 07:07 AM

View Postariebsomer, on 25 August 2010 - 12:24 PM, said:

I am porting a project from classic ASP to ASP.NET.

This application is an intranet site that connects with our application database to dynamically display data in various formats on the site.

Several pages of the site have a filterbar and toolbar on them that allows for things like print screen, export to Excel, add to favorites, and a kind of GUI interface to allow for the creation of some SQL filtering.

So originally, there was an ASP file called toolbar that never really got displayed, it was just an asp file that was included in whichever pages needed to display the toolbar.

However, now with this being ASP.NET, there are no more includes statements, and since this isn't really a 'page' so much as a collection of subs and functions, I just made it a class file to be referenced as needed by the pages that have a toolbar.

But the toolbar buttons are all javascript-driven. So I have a toolbar.js file with all of the javascript functions needed by toolbar.vb, but for some reason they aren't working. Each sub in the toolbar.vb class file has this if statement:

'javascript file call
            If (Not ClientScript.IsStartupScriptRegistered("javascript")) Then
                ClientScript.RegisterStartupScript(Me.[GetType](), "MyScript", "<script language=javascript src='toolbar.js'></script>")
            End If


I figured this should detect if the RegisterStartupScript had been initialized already or not and if not, initialize it.

The only thing I can figure is that since the class file sites in the App_Code folder, the js may not be getting accessed. On all of my regular pages, I couldn't access any javascript in a subfolder (no matter what pathway syntax I tried) and had to put the .js files in the root directory.

Anyone?


Solved. Just had to include the .js file for my toolbar in the actual page(s) using it. That way, when the class file with all the subs that controls the toolbar is referenced, all of the javascript is already available to the page, instead of trying to 'chain' the javascript through the class file first.
Was This Post Helpful? 0
  • +
  • -

#4 Frinavale   User is offline

  • D.I.C Addict
  • member icon

Reputation: 205
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Calling JavaScript in class file

Posted 26 August 2010 - 07:25 AM

Thanks for providing more details about the feature you're working on :)
I recommend that you move this code out of the "class" that you have it in and create a Web User control.

Web User Controls are sort of like ASPX pages except they aren't... hmm... They are implemented like an aspx page (they have the same life cycle etc as an aspx page). You can add this control to many web pages in your website though.

So, you would create a web user control for your toolbar.
You would place elements on the "page" (of the web user control) that the user will use to interact with your toolbar....in the C#/VB.NET server-side code you will register your Javascript for the control with the Page that the control is a part of (this way you can check to see if it's been registered or not).

After you're finished designing/implementing the control you can add it to the pages that need to use it.

-Frinny
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1