Recently i have been trying to jQuery with ASPX page which works fine
but if the aspx page is a content page of some master page i have issues.
The issue is
I pass my ASP control id directly to jQuery but if that control is on content page the control name changes as master page adds additional information infront of the control name in the browser.
e.g:
ASP Image ID:imgCrop changed to ctl00_MainContent_imgCrop where
MainContent is the name of Content place holder.
Is there way to sort out this issue?
or i rather pass this id ctl00_MainContent_imgCrop to jQuery? Which i am already doing and seems to work fine.
Windows 8 Professional 64 Bit.
Visual Studio 2012
Sql Server 2012
-------------------------------------
www.HermesWritings.com
Yes, if you use master pages and user controls clientids of server controls will change.
You can hard code the values as you are doing right and send it to jQuery but its not preffered. Because if there is any name change of user control or master page, again you need to go to all your pages and manually change things.
Instead, if you have all your controls in a page you can pass ClientID property of control. For ex:<%=txtName.ClientID%>
This way you will have clientid's of server controls.
Thanks,
Sundeep Podugu
My Blog --------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
Thanks,
Sundeep Podugu
My Blog --------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
Marked as answer by bhanu2217 on May 03, 2010 09:25 AM
bhanu2217
Member
527 Points
458 Posts
jQuery with Master Pages
May 02, 2010 10:02 AM|LINK
Recently i have been trying to jQuery with ASPX page which works fine
but if the aspx page is a content page of some master page i have issues.
The issue is
I pass my ASP control id directly to jQuery but if that control is on content page the control name changes as master page adds additional information infront of the control name in the browser.
e.g:
ASP Image ID:imgCrop changed to ctl00_MainContent_imgCrop where MainContent is the name of Content place holder.
Is there way to sort out this issue?
or i rather pass this id ctl00_MainContent_imgCrop to jQuery? Which i am already doing and seems to work fine.
Visual Studio 2012
Sql Server 2012
-------------------------------------
www.HermesWritings.com
sundeep_38
Contributor
3541 Points
604 Posts
Re: jQuery with Master Pages
May 02, 2010 12:20 PM|LINK
Hi,
Yes, if you use master pages and user controls clientids of server controls will change.
You can hard code the values as you are doing right and send it to jQuery but its not preffered. Because if there is any name change of user control or master page, again you need to go to all your pages and manually change things.
Instead, if you have all your controls in a page you can pass ClientID property of control. For ex:<%=txtName.ClientID%>
This way you will have clientid's of server controls.
Sundeep Podugu
My Blog
--------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.
bhanu2217
Member
527 Points
458 Posts
Re: jQuery with Master Pages
May 03, 2010 02:35 AM|LINK
so if this is my present jQuery where i have hardcoded
jQuery(document).ready(function() { jQuery('#ctl00_MainContent_imgCrop').Jcrop({ onSelect: storeCoords }); });I should change it to this?
jQuery(document).ready(function() { jQuery('#imgCrop.ClientID').Jcrop({ onSelect: storeCoords }); });imgCrop is the ID i am using for a ASP Control.
Visual Studio 2012
Sql Server 2012
-------------------------------------
www.HermesWritings.com
sundeep_38
Contributor
3541 Points
604 Posts
Re: jQuery with Master Pages
May 03, 2010 05:14 AM|LINK
If imgCrop is server side control and this function is placed in aspx page. Code will change this way
jQuery(document).ready(function() {
jQuery('#<%= imgCrop.ClientID%>').Jcrop({
onSelect: storeCoords
});
});
Sundeep Podugu
My Blog
--------------------------------------------------
If there is any mistake/suggestion in any of my conversation in this forum, please let me know.