Click here to Skip to main content
15,896,432 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wanted to create one master page and two content pages. i just want to use javascript for login validation .head tag is just appear in master page only and we r just writing our javascript code in head tag .and if i write coding in head tag then it may affect on another content page .so in that condition where to write our javascript code
Posted
Comments
Sergey Alexandrovich Kryukov 7-Nov-11 1:21am    
What's wrong about having scripts in head tag and affecting another page?
--SA

Hi when we use master page in our aspx page there are two contentplaceholder.
you can create new contentplaceholder and write there your Javascript.
 
Share this answer
 
v2
 
Share this answer
 
in ur page there must be two contentplaceholder one head & second Maincontent place ur javascript in
first section that is head
 
Share this answer
 
You can write javascript code in containt page like this.
If you are satisfy with this answer then Accept this solution.
----------------------------------------------------
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript" src="js/Common.js"></script>
    <script type="text/javascript">
        function IsMobileNoLength(txtBox) {
            var iCount = txtBox.value.length;
            if (iCount > 0) {
                if (iCount < 10) {
                    alert("Enter valid contact number.");
                    document.getElementById("<%=txtPhoneNo.ClientID %>").focus();
                }
            }
        }
        
    </script>
 
Share this answer
 
v4
As we have ContentPlaceHolderID in Content page wich reffers to a place in Master page,
So
C#
<head>
<asp:contentplaceholder id="HeadContent" runat="server" xmlns:asp="#unknown">
    </asp:contentplaceholder></head>


in master page..
and add content(javascript) to this place from ContentPage

As Shown..
ASP.NET
<asp:content id="HeaderContent" runat="server" contentplaceholderid="HeadContent" xmlns:asp="#unknown">
<script type="text/javascript">
function Validate(User)
{
}
</script>
</asp:content>
 
Share this answer
 
if you write javascript code in master page.it will refer in all the pages that inherit from the masterpage.

instead of that you what you can do is set some page as (which inherited from master page) as start up page(by write click that page in solution explorer).

then write the login function and validation inside that page. You can write javascript code inside other pages which inherit from master page.
write javascript code out side the all html elements.
ex:
<script type="text/javascript">
    function myfunction(txt) {
        alert(txt);
        var x = document.getElementById(txt);

        for (i = 0; i < x.Items.length; i++) {
            var tag = Items[i];
            alert(tag.getAttribute("id"));
            //atags += tag.getAttribute("id") + "|";
           // atags += tag.getAttribute("href") + "|";

        }
       // alert(x.url);
    }
</script>

or the else you can use page that does not inherit from master page as start up page and use all login validation inside that page. then if the valid login, transfer to the page which inherit from master page.
 
Share this answer
 
v2
nothing wrong if you write code in master page head

and you can also write code in content page

in content page you can write javascript in this tag
<asp:content id="Content1" contentplaceholderid="head" runat="Server" xmlns:asp="#unknown">
<script runat="server">
functin fn()
{}
</script>
</asp:content>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900