Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have used .js file and in .js file i have made javascript.i have used masterpage to make form.now in this form i want to apply javascript.then link ...
<script src="javascript/TextboxValidation.js" type="text/javascript"></script>

where i have to put?.i have put this in mastrpage which i have shown below,but it is not working.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />

    <script src="javascript/JScript1.js" type="text/javascript"></script>
    <script src="javascript/print.js" type="text/javascript"></script>
    <script src="javascript/TextboxValidation.js" type="text/javascript"></script>
Posted
Updated 24-Jan-13 19:06pm
v2
Comments
Abhishek Pant 25-Jan-13 1:10am    
check your javascript.
Member 9511889 25-Jan-13 1:21am    
my javascript is working perfectly in form without masterpage
Are you sure about the paths of those script files?
Member 9511889 25-Jan-13 1:27am    
yes
Do you have firebug?
If you have just enable that while loading your page and see on the script tab.
You will find all the script files in the dropdown.
Please see if those script files are there or not?

Problem
The ID of controls present in the content page will be changed if master page is used during rendering.

For your textbox
XML
<asp:TextBox ID="txt_TotalFees" runat="server" Width="200px" onblur="SurName()" Enabled="false">

The id txt_TotalFees will become something like 'ctl00_ContentPlaceHolder1_txt_TotalFees' (not exact).

You can see this by viewing the source of the webpage in the browser.

Solutions
1. ClientID, if you are writing this in content aspx page (not your case).
JavaScript
var x = document.getElementById("<%= txt_TotalFees.ClientID %>");

It will not work in External js file.

2. Declare a global js variable in the aspx file and set it to the ClientID value. Now in the external is file you can use getElementById on this var.
Refer - How to get client id at external javascript file[^]

2. ClientIDMode.Static (try this one)
You can use this one. Just add this attribute to the textbox like below.
XML
<asp:TextBox ID="txt_TotalFees" runat="server" Width="200px" onblur="SurName()" Enabled="false" ClientIDMode="Static">

So, after rendering in browser the ID will be the same as txt_TotalFees.

Then, the below line in External js will work.
JavaScript
var x = document.getElementById("txt_TotalFees");

To know more about the ClientIDMode refer - ASP.NET 4.0 : Manipulate ClientID using ClientIDMode[^]
Try this solution and let me know.

Thanks...
 
Share this answer
 
v2
Comments
[no name] 25-Jan-13 5:30am    
+5...
Thanks @Sisir.
[no name] 25-Jan-13 5:42am    
yw
HI,

Make sure that you have added the following file to tour master page.

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

Add this in the master page and then the following bunch of code in the page where the control present.

function SurName() { var x = $("#txt_TotalFees"); x.value = x.value.toUpperCase(); }


This is needed to know the page about the scripts.

Thanks
 
Share this answer
 
v2
Comments
Abhishek Pant 25-Jan-13 1:35am    
the OP is sure about javascipt path.
Member 9511889 25-Jan-13 2:24am    
i have try this,but not working
[no name] 25-Jan-13 2:36am    
Can you show which bunch of code you are trying and not working f or javascript?
Member 9511889 25-Jan-13 3:02am    
function SurName()
{
var x = document.getElementById("txt_TotalFees");
x.value = x.value.toUpperCase();

}
this is my javascript in .js file.

<asp:TextBox ID="txt_TotalFees" runat="server" Width="200px" onblur="SurName()" Enabled="false"
>
onblur in textbox code.
Do you have firebug?
If you have just enable that while loading your page and see on the script tab.
You will find all the script files in the dropdown.
Please see if those script files are there or not?

The problem is in function
C#
function SurName()
{
    var x = document.getElementById("txt_TotalFees");
    x.value = x.value.toUpperCase();
}

If you use master page in your web site or web app it will change your control id's dynamically after post back,you can check this with view source option after rendering the output by right clicking on the page.
So problem is with this statement,
C#
document.getElementById("txt_TotalFees");

here your js is not getting "txt_TotalFees" particular ID.

so better solution to this is set
C#
ClientIDMode="Static" attribute to each and every control on your page

please refer this to get info about ClientID property..

Happy Coding..... :)
 
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