Q: Common code for an .ASPX page?

  • Thread starter Thread starter Visual Systems AB \(Martin Arvidsson\)
  • Start date Start date
V

Visual Systems AB \(Martin Arvidsson\)

Hi!

When i develop my web application i have a set of javascript that is used in
several pages.
Also the title is the same for all pages. And certain controls have events
that are in the
javascript..,.

Is it possible to assign the .JS file to be global all over the project
without
having to add the <Script>/java/my.js....</script> on every page
and also when the TextBox is added i always want the onchange="xxx" to be
set...

Hope you understand what i mean...

Regards

Martin Arvidsson
 
This might be what you are looking for. You will add your own page template
for the items->new dialog window within studio. That way all the new pages
you add to your solution will have the same layout as your template.

http://www.kbalertz.com/Feedback_870715.aspx

If you are just wanting to register a script block, you might want to look
at deriving your own page class, overriding the OnLoad and registering your
script block.

Then in all your pages in the solution, you can derive from your own page
instead of System.Web.UI.Page, then you won't have to worry about anything.

I would recommend a combination of both, that way you can have a shared code
region for all your pages, and get the template layout that you want
regarding HTML.

For the TextBox control to always have a onchange wired, derive your own
TextBox from System.Web.UI.WebControls.TextBox and in the constructor, set
the onchange event.

Then drop your derived TextBox on the webform and all your TextBox es will
have the onchange "wired" to.

HTH,

bill
 
Hi
you can make a custom control named base page which must be direved from
Page. You should override prerender event and put your script to be
registered like this :
RegisterClientScriptBlock(ScriptKey, "<script language=\"Javascript\"
src=\"Scripts/Common.js\"></script>");
and you can make a method to search all of your controls in page and add the
event on it.

something like this
private void aa(System.Web.UI.Control ctrl){
foreach(System.Web.UI.Control c in ctrl.Controls){
if(c is TextBox){
((TextBox)c).Attributes.Add("onchange","script"); }
aa(c);
}
}
and on prerender call aa(this.controls);

And after this you should derive all of your forms from this one not from
System.Web.UI.Page.
Cheers
 
Back
Top