Click here to Skip to main content
15,918,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends

i have one master page in which i have taken 1 form tag
like
ASP.NET
<form id="form1" runat="server"> </form>


and i want to use validation engine of jquery which is only applicable on form tag
So i want this id to be available in my child page so that i can use it.
like
JavaScript
$(document).ready(function() {
           $("#form1").validationEngine('attach');
       });

so please help me to resolve this issue...
thanks in advance
Posted
Updated 29-May-12 5:12am
v4

Hi guys I too was facing the same problem, finally i got the solution.
Just copy the below code and paste it in the child page's header content.

XML
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery('#' + '<%=Master.FindControl("form1").ClientID %>').validationEngine();
    });
</script>
 
Share this answer
 
In general master page and child page are rendered together. At the end (the point where all DOM is ready, and your jquery statement runs) you will have both as html code. Look at the generated source in IE and see how the master page form's ID looks like. Use that ID if it is not changing, or the generated one. See: http://msdn.microsoft.com/en-us/library/system.web.ui.control.uniqueid.aspx[^]
 
Share this answer
 
Comments
preet88 29-May-12 13:32pm    
i have tried that client id as well but not able to access
however without doing so in simple page i.e without master page is working well
So please if you can provide me the way to access that then it'll be great!!!
i've tried using this code '<%=form1.ClientId%>' to have client id in document ready
Rahul Rajat Singh 30-May-12 1:14am    
are you not missing a # in the jQuery selector. since if you need to select using ID we need to use # too.
The ID of the form might be different than what you are using. you are using the server side id of the control use this instead:

JavaScript
$(document).ready(function() {
            $('#=<%form1.ClientID%>').validationEngine('attach');
        }); 
 
Share this answer
 
In HTML view there is no difference in master page or child page, all are rendered as a single page. So you can access the master page control from js.

While using the <%= xx.ClintID%> tag you need to put it in aspx page. It may not work in a separate js file.

Now as you are saying that <%= xx.ClintID%> is not working... I think you are putting the code in either child controls aspx page or in a separate js file.
In case of child.aspx page form1.ClientID will not work, because form1 is not accessible from child control.

I can sujjest that you keep a js variable in master pages's aspx file like....
var myFormID = '<%= form1.ClientID%>';

and in child page you use ...
$(document).ready(function() {
$('#'+myFormID ).validationEngine('attach');
});

Hope this will work
 
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