Jquery introduction and How to use jquery with Asp.net Masterpage and Simplepage
jquery is javascript library developed to simplify the client-side scripting of HTML,event handling and animation on client side. Jquery power making its slogan is very true "Write less do more".
Why we should use Jquery ?
before reading anything i always raise above question to Google :) .
In Case of Jquery , i am giving the answer -
jquery simplifies javascript programming and ensures us to run on Every Browser available on the internet.we can do javascript code with Jquery. Jquery use chaining mechanism while writing codes which makes it more easy to write and understandable.
jquery simplifies javascript programming and ensures us to run on Every Browser available on the internet.we can do javascript code with Jquery. Jquery use chaining mechanism while writing codes which makes it more easy to write and understandable.
Including Jquery in Asp.net -
To include jquery, first download the latest version at www.jquery.com and unzip or copy the file to the root directory of your website project (in other words, where your default.aspx, index.html or index.php file is).
Microsoft Visual studio 2010 and 2012 including jquery by default and providing intellisense to use jquery.
After downloading jquery you can add this in head of your Asp.net page(Simple or master)-
<script src = 'jquery-1.7.1.min.js' type = 'text/javascript'></script>
Tip : using google ajax libraries to add jquery has several advantage decreased latency ,increased parallelism and provide better caching.
You can add this into head
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
and missing http: is'nt a mistake ,that’s a helpful trick which allows you to use a single reference that works on both HTTP and HTTPS pages.and protocol less fetch jquery library directly from disk to browser which increase the speed bit as well ;).below images will prove the speed test.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
you can see the timeline of link without protocol is 14ms which is the fastest in comparison to others.
Access Asp.net master page control with Jquery -
Ensure that if you have already included jquery in your master page , don't include this in you content page .
because while rendering in browser asp master page and content page gets merged and browser always executes from top to bottom.
How to access elements in master page using jquery -
Below I've put some code sample which I've used to get jquery to find .net controls. because its hard to find the controls due to dynamic nature and asp.net controls such as Master page, login control and Grid view elements.
Solution1 :
input[id$=TextBox]
The above line matches all HTML input elements with an id attribute that ends with "MyTextBox".
It will match:
<asp:TextBox ID="ctl00$TextBox" runat="server"/>
<asp:TextBox ID="LaLaLaTextBox" runat="server"/>
<asp:TextBox ID="HehahaTextBox" runat="server"/>
Example -
$(document).ready(function () { //write your code here var txt =$('input[id$=TextBox2]').val(); });
Solution2:
Using client ID For Asp.net Page-
The client ID of the control won't be known until the page is produced, So you can use predictable
client id using jquery # and id given by you.
$('#' + '<%=label1.ClientID %>')
or
$('#<%=Label1.ClientID%>').text();
Example -
$(document).ready(function () { //write your code here var lbltext = $('#' + '<%=lbl.ClientID %>').text(); $('#' + '<%=TextBox4.ClientID %>').val(lbltext);
});
Solution3:
finding it with attribute -
$("[id$=_txtSymbol]").attr("id")
Also realize that doing attribute selector searches are fairly slow (but then ‘slow’ is relative). If you have very large documents with lots of elements and you’re doing many look ups using this function you may run into slow performance issues.
you can download the working code from Here .
This comment has been removed by the author.
ReplyDeleteMy pleasure sir ... :)
ReplyDeleteExcelente, Gracias por la Ayuda.
ReplyDeleteThank you...
ReplyDeleteThis is extremely helpful info!! Very good work. It is very interesting to learn and easy to understood. Thank you for giving information. Please let us know and more information get a post to link.Data Science Training | Data Science Online Training
ReplyDeleteReally very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up…
ReplyDeleteStart your journey with SAP S4 HANA Simple Logistics Training in Bangalore and get hands-on Experience with 100% Placement assistance from experts Trainers @Softgen Infotech Located in BTM Layout Bangalore. Expert Trainers with 8+ Years of experience, Free Demo Classes Conducted.
Awesome,Thank you so much for sharing such an awesome blog.
ReplyDeletesap hr courses in bangalore
sap hr classes in bangalore
sap hr training institute in bangalore
sap hr course syllabus
best sap hr training
sap hr training centers
sap hr training in bangalore
This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteweb designing training in chennai
web designing training in tambaram
digital marketing training in chennai
digital marketing training in tambaram
rpa training in chennai
rpa training in tambaram
tally training in chennai
tally training in tambaram
I must appreciate you for providing such a valuable content for us. This is one amazing piece of article. Helped a lot in increasing my knowledge
ReplyDeletejava training in chennai
java training in porur
aws training in chennai
aws training in porur
python training in chennai
python training in porur
selenium training in chennai
selenium training in porur
Given so much information in it. its very useful .perfect explanation about Dot net framework..
ReplyDeletehadoop training in chennai
hadoop training in omr
salesforce training in chennai
salesforce training in omr
c and c plus plus course in chennai
c and c plus plus course in omr
machine learning training in chennai
machine learning training in omr
Nice blog to read, Thanks for sharing this valuable article.
ReplyDeleteBest Apache Spark Online Course
Apache Spark Training Institute in Pune