473,378 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Q: Common code for an .ASPX page?

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

Nov 18 '05 #1
2 1438
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

"Visual Systems AB (Martin Arvidsson)" <ma**************@vsab.net> wrote in
message news:ul**************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #2
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
"Visual Systems AB (Martin Arvidsson)" wrote:
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

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex Maghen | last post by:
Let's say I am building a web site that will have many ASPX pages and I want to implement a lot of common page- level functionality globally (centrally). Examples include: * Setting the TITLE...
1
by: richardlane | last post by:
Hi, basic question here - I'm struggling with the transfer from asp to asp.net a bit, especially in seeing the 'bigger picture' of how things are best structured. I have a website made up...
2
by: Wayne J | last post by:
I have 3 pages, each with 2 tables (tblNew and tblConfirm), because these 2 tables are affected by the same code, I thought if I used an inherited class defining these variables along with the...
1
by: bminder | last post by:
In the asp.net pages below, Common.vb has an overridable Page_Load sub. In the consuming page, Two.aspx, the Page_Load sub is inherited, but for some reason it (Overrides Sub Page_Load) executes...
4
by: Vladimír Kolesnik | last post by:
Hi there, does anybody know, how to create a class, which is can be inherited by both aspx (System.Web.UI.Page) as well as by ascx (System.Web.UI.UserControl) classes. I have the bunch of same...
6
by: Don Wash | last post by:
Hi All! I'm developing ASP.NET pages using VB.NET language. My background is VB6 and ASP3. Right now, I'm evaluating strategies on creating reusable and common functions and methods for ASP.NET....
7
by: J Smithers | last post by:
I have several ASPX pages (with code-behind logic) that I reuse amongst many Web sites on the same production server. Currently each Web site has its own copy of these aspx pages. I was thinking...
5
by: Amelyan | last post by:
I am struggling here trying to determine what is a good programming practice as far as referencing your URLs. When you use Response.Redirect, do you use 1) Hard-coded string --...
3
by: stumay111 | last post by:
I am working in VS 2003, using VB.NET. I have a series of pages with forms on them, an application for a DOT number for motor carriers. The code behind them iterates through the controls on the...
4
by: jmacduff | last post by:
I have a set of pages ( about 10 ) that all have the same controls at the top, however I am unable to put the controls the master page for the site since the other 50 pages dont have the controls....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.