ishoo agarwal
ishoo agarwal

Reputation: 66

Call c# method on click of <li>

I have a project which have multiple tabs in

<li id=tab1 class="active"><a href="#">Tab1</a></li>
<li id=tab2><a href="#">Tab2</a></li>
<li id=tab3><a href="#">Tab3</a></li>
<li id=tab4><a href="#">Tab4</a></li>

Each tab have multiple gridviews
When the page_Load is called it executes more than 10 methods which have almost 15 queries, which makes the page really slow.

I want to call the methods on click of the tab
Only relevant method on the relevant TAB

Remeber when the page is postback the Tab1 becomes the active tab

Upvotes: 1

Views: 2204

Answers (2)

user3875617
user3875617

Reputation:

<li runat="server" id=tab1  OnClick="Ontabl1_Click">....</li>

Then

public void Ontabl1_Click(object sender, EventArgs e)
{
  // sender is the li dom element you'll need to cast it though.
}

Try like this for Javascript

<script>
function fntabl1(str) {
    //your code
}
</script>

<li onclick="fntab1(this.id)" id="tabl">....</li>

Upvotes: 3

Shetty
Shetty

Reputation: 1892

Add runat= server attribute to each tag. Write OnClick method for each of them. In the click method on server side load the corresponnding gridview.

Upvotes: 0

Related Questions