[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

jQuery and GridView question

Posted on 2011-03-15
3
Medium Priority
?
443 Views
Last Modified: 2012-05-11
Hi,

I am trying to use jQuery with a GridView but having trouble making it work.  The markup for a gridView looks as follows (abbreviated version):

<asp:TemplateField HeaderText="Start Date">
<EditItemTemplate>
   <asp:Button runat="server" ID="btnShowCalendar" CssClass="CalendarDiv" onClientClick="return false" Text="..." />

   <div style=display:none">
      <asp:Calendar id="calStartDate" OnSelectionChanged="calDate_SelectionChanged" Runat="server" />
   </div>
</EditItemTemplate>
</asp:TemplateField>

Similiar code has been applied to several other date type columns

my jQuery looks something like the following:

$('.CalendarDiv').click(function(event)
{
   alert( this.id );
   $(this).next().toggle('slow');
}

What I am trying to accomplish is to set the visiblity of the div tag on/off when a user clicks on the button inside the EditItemTemplate.  Problem is that this function is being called multiple times.  The more records I have, the more times this function is called.  Makes sense as I have many buttons that has the "CalendarDiv" class applied to them.  How can I make this function call only once?

thank you.
0
Comment
Question by:yechan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
devlab2012 earned 2000 total points
ID: 35140969
Change your code to:

$('.CalendarDiv').click(function()
{
   alert( this.id );
   $(this).next().toggle('slow');
});
0
 
LVL 13

Expert Comment

by:devlab2012
ID: 35140996
Where have you written the jquery code on your page? I think you have that code somewhere in the GridView markup. Try using the following code in the <head> section of the page.

$(document).ready(function()
{
  $('.CalendarDiv').click(function()
  {
     alert( this.id );
     $(this).next().toggle('slow');
  });
});
0
 
LVL 1

Author Comment

by:yechan
ID: 35142535
Hey devLab,

the query itself is embedded inside a seperate *.js file.  The GridView is a user control which is eventually embedded/added to a web part page.  Do you think that makes a difference?
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question