Learn How to Use JQuery With MasterPages in ASP.NET 4.0
Yes, it is possible to find a good web host. Sometimes it takes a while to find one you are comfortable with. After trying several, we went with Server Intellect and have been very happy thus far. They are by far the most professional, customer service friendly and technically knowledgeable host we’ve found so far.
To begin, create a new ASP.NET Empty Web Site in Visual Studio. First, we will need to add a reference to JQuery. If you don’t have JQuery you can download it at http://jquery.com/. Once you have it, you are ready to add it to your project. To do this:- Right click the project in your solution explorer.
- Select ‘Add Existing Item…’.
- Navigate to your JQuery file and select it.
- Click add.
- Right click the project in your solution explorer.
- Select ‘Add New Item…’.
- Select a master page and name it ‘MasterPage.master’.
- Click add.
<head runat="server"> <title></title> <!-- We add all of our external references for our pages here --> <script src="jquery-1.6.js" type="text/javascript"></script> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder> </head>
- Right click the project in your solution explorer.
- Select ‘Add New Item…’.
- Select a new ASP.NET page and name it ‘Default.aspx’.
- Click the ‘Select master page’ check box.
- Click add.
- Select ‘MasterPage.master’ and click OK.
I just signed up at Server Intellect and couldn’t be more pleased with my fully scalable & redundant cloud hosting! Check it out and see for yourself.
Cool, we now have a new page using our master page. This page contains two Content sections that correspond to the ContentPlaceHolder sections of our master page. In this case, we will add some test code to our ‘head’ content section which will use some JQuery. It is important to note that this will work here only because we have configured our master page to have a reference to JQuery before our scripts on this page are read.To this page, go ahead and add a new button with a Text property of ‘Click Me’, and an OnClientClick property of ‘ButtonClick()’. Next, add the following code to the ‘head’ content section:
<script type="text/javascript"> function ButtonClick() { alert($('#ContentPlaceHolder1_Button1').val()); } </script>
Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.
To test this out, load up the web site and click the button. You should see an alert box that displays the message ‘Click Me’ which corresponds to the text in our button. This demonstrates how to set up your master pages to work easily with JQuery. I hope that this helps, happy coding!Using JQuery With MasterPages asp4 cs

One Response
5.24.2011
nice