Avatar of zachvaldez
zachvaldez
Flag for United States of America asked on

Focus on same tab after selecting in a dropdown list

I have two tabs in the form and a dropdownlist.
Even when I'm on Tab2 when I select a value, the page defaults back to tab 1 after postback. What can I do to maintain default on Tab2 upon postback
ASP.NETC#

Avatar of undefined
Last Comment
zachvaldez

8/22/2022 - Mon
Prakash Samariya

How do you make a tab in asp.net (using html, asp.net control, jQuery etc.)?
Could you please provide your part of code to look into it?
zachvaldez

ASKER
  <div class="row">

            <div class="col-md-4">
                <asp:DropDownList ID="ddlAccount" runat="server" OnSelectedIndexChanged="ddlAccount_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
            </div>
            
        </div>
         

        <ul class="nav nav-tabs">
            <li class="active"><a href="#tab1" data-toggle="tab">Trade A</a></li>
            <li><a href="#tab2" data-toggle="tab">Trade B</a></li>

        </ul>

Open in new window

zachvaldez

ASKER
Like I mentioned, If I go to Tab2 and pick a value in dropdownlist, it goes back to Tab1
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
zachvaldez

ASKER
I have not gotten response on this?
Prakash Samariya

It seems you have created Tabs using CSS & Javascript/jQuery!
<ul class="nav nav-tabs">
            <li class="active"><a href="#tab1" data-toggle="tab">Trade A</a></li>
            <li><a href="#tab2" data-toggle="tab">Trade B</a></li>
        </ul>

Open in new window

If yes, then you should following things
1. When tab changes, put active tab in the URL like http://yoururl#tab1
2. on document.ready method manipulate # and call your function which toggle tabs.
zachvaldez

ASKER
Prakash, Thanks for the idea but can you post the code.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Prakash Samariya


Prakash, Thanks for the idea but can you post the code.
I hope, if you implement using my idea will also work if you know how to do it using javascript/jQuery, same you did to toggle tabs!

You could check below link for reference
https://codepen.io/angelorubin/pen/qZzjdX
zachvaldez

ASKER
The dropdown selectedchanged index event is csausing the tab to focus on the first tab which is the default,
ASKER CERTIFIED SOLUTION
Prakash Samariya

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
zachvaldez

ASKER
Thanks Prakash,
I know you want to help but without providing code to how it work, I would consider it only as a suggestion and not a solution.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Prakash Samariya

Thanks zachvaldez for reply.
Did you understand what I was trying to explain in my solution?
If you do that way, you will get resolution! You could reply if you have implementation issue or error you found in it!
All the best :)
zachvaldez

ASKER
The dropdown is outside the tabs
as this shows. So I don't think solution would work. If I'm on tab2 and pull down the dropdown and select it jumps to Tab1

         
  <h3>Worksheet</h3>
        </header>
        <div class="row">

            <div class="col-md-4">
                <asp:DropDownList ID="ddlAccount" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlAccount_SelectedIndexChanged"></asp:DropDownList>
            </div>
            <div class="col-md-1">
                <asp:Label ID="lblFiscalYear" runat="server" Text="2018"></asp:Label>
            </div>
        </div>
       
        
        <ul class="nav nav-tabs" role="tablist" id="myTab">
            <li class="active" role="tab"><a href="#tab1" data-toggle="tab">Tab1</a></li>
            <li><a href="#tab2" role="tab" data-toggle="tab">Tab2</a></li>

        </ul>

Open in new window

zachvaldez

ASKER
This is the closer solution  submitted because I have no choice
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.