473,396 Members | 2,052 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,396 software developers and data experts.

javascript in content pages

Hi,

I have a master page and content page. In content page I have to
validate the text boxes for
name,address, phone number and email address etc. But as content pages
doersn't have html section not head or body section so, where I use
this java script in content page to validate the form.

Thanks

May 2 '07 #1
3 14767
<bb****@yahoo.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
I have a master page and content page. In content page I have to
validate the text boxes for
name,address, phone number and email address etc. But as content pages
doersn't have html section not head or body section so, where I use
this java script in content page to validate the form.
Anywhere you like - I usually put it at the very beginning of the content
page...

--
http://www.markrae.net

May 2 '07 #2
Use the RegisterClientScriptBock method. Example:
--codebehind for somepage.cs, which uses a masterpage (although this doesn't
matter)

Page.aspx:
<input type="button" onclick="something();" value="click me" />

Page.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
Page.RegisterClientScriptBlock("uniqueString", "<script
type=\"text/javascript\">function something(){
alert('something'); }</script>");
}
Doing the Javascript construction in the .cs file can get annoying and
messy, so I will often put the javascript in the aspx (or ascx) file in a
literal control that I never display, but read the contents of, like so:

Page2.aspx:
<input type="button" onclick="somefunction();" value="clickme" />
<asp:Literal ID="litClientScript" runat="server" Visible="false">
<script type="text/javascript">
function somefunction() {
var x = 3;
var y = 9;
alert(x*y);
}
</script>
</asp:Literal>
Page2.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
Page.RegisterClientScriptBlock("clientScript", litClientScript.Text);
}

Ray at work


<bb****@yahoo.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
Hi,

I have a master page and content page. In content page I have to
validate the text boxes for
name,address, phone number and email address etc. But as content pages
doersn't have html section not head or body section so, where I use
this java script in content page to validate the form.

Thanks
May 2 '07 #3
Mark is correct that this will work. You can put javascript anywhere you
like. Purists would advise against it, but in reality, it'll still work
just the same. The one problem you can run into is the way that javascript
is loaded and executed at the same time, so if you call something that
appears higher up in the page, you'll get an error in the browser. Example:

<body>
<script type="text/javascript">
somefunc('first call'); //this will fail here
</script>

<script type="text/javascript">
function somefunc(s) {
alert(s);
}
</script>

<script type="text/javascript">
somefunc('second call'); //this will work
</script>
</body>

Ray at work
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:u2**************@TK2MSFTNGP05.phx.gbl...
<bb****@yahoo.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
>I have a master page and content page. In content page I have to
validate the text boxes for
name,address, phone number and email address etc. But as content pages
doersn't have html section not head or body section so, where I use
this java script in content page to validate the form.

Anywhere you like - I usually put it at the very beginning of the content
page...

--
http://www.markrae.net
May 2 '07 #4

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

Similar topics

1
by: dezza | last post by:
Hi, I am developing a web application that is a series of pages, rather like a wizard. Because all of the pages basically have the same navigation, and require the navigation buttons in the...
3
by: Chris Lincoln | last post by:
I am currently working on a company site and have run into a problem with the search aspect of the site. I am running .net 2.0 and iis 5.1. The issue is as follows: Indexing Service is properly...
3
by: vikramp | last post by:
Hi, I am still new to ASP.NET 2.0 and trying to develope something using Master pages. My problem is: I have a master page that contains Logo image and a navigation menu at the top of the...
0
by: bobby421 | last post by:
Hi, I have a master page and content page. In content page I have to validate the text boxes for name,address, phone number and email address etc. But as content pages doersn't have html section...
2
by: Stratum | last post by:
It's an old question, and I apologize for raising it again. I use ImageButton objects on my ASP.Net master page to navigate to content pages. For each button, I have two images. One image shows...
0
by: kewldudehere | last post by:
Hi folks, I have a content Page and have the following Code in the content tag. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <input type="Text"...
1
by: krisviswa | last post by:
Hi I am new to web programming and I started working with Asp.net 3.5 vwd express edition with ajax tool kit.For about a week now I screened most of articles on use of javascript in asp.net and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.