2

I have several linkbuttons in my master page. I need to add css class "Active" after I click each linkbutton and postback URLs.

<asp:LinkButton ID="Linkbutton1" runat="server" PostBackUrl="/News.aspx?lang=1"
         Text="News" OnClick="Linkbutton1_Click">
</asp:LinkButton>

Linkbutton 1

Linkbutton 2 - class "active"

Linkbutton 3

I tried to add class using linkbutton onclick event, but after postback css class has been removed.

3 Answers 3

2

Put this to the Linkbutton1_Click method:

Linkbutton1.CssClass = "active";

Article on MSDN.

Sign up to request clarification or add additional context in comments.

4 Comments

I already said than i tried to use onclick event but after postbacking url, css class had been removed.
So, is News.aspx the different page?
yes it is. I am using masterpage, to load other content pages, news aspx is content page
I suppose, which button is active actually depends on ?lang=1 URL parameter value?
1

if you want write in code behind you can work with cookies:

in Linkbutton1_Click method:

Response.Cookies["Linkbutton1-cssClass"].Value = "active";

in Page_Load method:

if(Request.Cookies["Linkbutton1-cssClass"] != null)
   Linkbutton1.CssClass = Server.HtmlEncode(Request.Cookies["Linkbutton1-cssClass"].Value);

finaly you can use foreach for all LinkButtons

Comments

0

onclick of linkbutton call javascript function changestyle(SenderID)

<script type="javascript">
var strPreviousCahnge=""
function changestyle(SenderID)
{
   var LinkButtonActive=document.getelementbyid(senderID);
LinkButtonActive.className="subTabActive";

            if (strPreviousCahnge!= "" && strPreviousCahnge!= id)
            {
                var identity=document.getElementById(strPreviousCahnge);
                identity.className="subTabInactive";
            }
strPreviousCahnge=SenderID
}
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.