Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 24-Jan-13 19:03pm
Edited 24-Jan-13 19:06pm
v2
Comments
Abhishek Pant at 25-Jan-13 1:10am
   
check your javascript.
Member 9511889 at 25-Jan-13 1:21am
   
my javascript is working perfectly in form without masterpage
Tadit Dash at 25-Jan-13 1:26am
   
Are you sure about the paths of those script files?
Member 9511889 at 25-Jan-13 1:27am
   
yes
Tadit Dash at 25-Jan-13 1:33am
   
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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Problem
The ID of controls present in the content page will be changed if master page is used during rendering.
 
For your textbox
<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).
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.
<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.
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...
  Permalink  
v2
Comments
Tadit Dash at 25-Jan-13 5:32am
   
Thanks @Sisir.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Comments
Abhishek Pant at 25-Jan-13 1:35am
   
the OP is sure about javascipt path.
Member 9511889 at 25-Jan-13 2:24am
   
i have try this,but not working
Member 9511889 at 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.
Tadit Dash at 25-Jan-13 3:43am
   
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?
Member 9511889 at 25-Jan-13 3:03am
   
please ignore enabled='false'.
Member 9511889 at 25-Jan-13 4:52am
   
can we write jquery in .js file?
i have no knowledge of jquery.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4


The problem is in function
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,
document.getElementById("txt_TotalFees");
here your js is not getting "txt_TotalFees" particular ID.
 
so better solution to this is set
ClientIDMode="Static" attribute to each and every control on your page
 
please refer this to get info about ClientID property..
 
Happy Coding..... Smile | :)
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100