title: Handling click event without postback
body: <p>I have a listview that populates with data. This listview is inside a user control which sits inside a page called Preferences.aspx.  Today I am handling click event on each row meaning that involves posting back to server. </p>
  
  <p>Now, I have to put another user control on Preferences.aspx because there are group of more settings which need to be presented separately to users. I have added the new user control inside a separate tab on the page. This new tab has to be the first one to show when user lands on Preferences.aspx.</p>
  
  <p>Now the problem is that when user goes to second tab (user control with listview) and click on a row, a postback occurs. This puts the user on the first tab (newly added user control).</p>
  
  <p>So I wonder how can I get click event on a row without having to postback?</p>
  
  <p>Any ideas or suggestions are welcome.I am working in Asp.Net with C#.</p>
  
  <p>The code is:</p>
  
  <p>Markup inside the user control:</p>
  
  <pre><code>&lt;asp:TableRow runat="server" id="trVisitor" CssClass='&lt;%# GetRowClass()  %&gt;' &gt;
  
                     &lt;asp:TableCell ID="tdPicture" runat="server" Width="10" onclick='&lt;%# GetClickPostBack(Container.ItemIndex)  %&gt;'&gt;
                         &lt;div style="margin-top:1px;"&gt;
                             &lt;asp:Image ImageUrl=' &lt;%# Page.ResolveUrl("~/" + Eval("Visitor.StatusImageUrl")) %&gt;' visible='&lt;%# historyFlag ? false : true %&gt;' runat="server"/&gt;
  
                             &lt;/div&gt;
  
                     &lt;/asp:TableCell&gt;
  </code></pre>
  
  <p>... and so on</p>
  
  <p>Markup inside Preferences.aspx:</p>
  
  <pre><code>&lt;ABC:ListControl runat="server" ID="visitorListControl" CanSelect="true" IsMine="true" Recurring="false" OnVisitorSelected="ListControl_VisitorSelected" /&gt;
  </code></pre>
  
  <p>And code behind is:</p>
  
  <pre><code>protected string GetClickPostBack(int itemIndex)
      {
          if (CanSelect)
              //return 0.ToString();
              return "javascript: " + Page.ClientScript.GetPostBackEventReference(this, VisitorRowPrefix + itemIndex) + "; return false;";
          else
              return string.Empty;
  
      }
      public void RaisePostBackEvent(string eventArgument)
      {
          if (eventArgument.StartsWith(VisitorRowPrefix))
          {
              HandleRowClick(Convert.ToInt32(eventArgument.Substring(VisitorRowPrefix.Length)));
          }
      }
  
      private void HandleRowClick(int index)
      {
          int CmgVisitorId = Constants.NotConfigured;
       //   bool IsHistoricVisitor = false;
        //  Visitor HistoricVisitor = new Visitor();
          // Mark only the clicked row
  </code></pre>
  
  <p>... and so on.</p>