Change AnchorLink Text on ASP.Net Button Click using C# and VB.Net

kevinf
 
on Jul 26, 2022 12:43 AM
791 Views

I currently use If textdesc = "" Then textdesc = "textblack" lFound.Attributes.Add("Class", textdesc) to set the lFount color to the users selection depending on the background (different colors white black etc). Can I use similar to set the navbar menu text the same in the <a href="about-section" see attached I currently use class="icon-import_contacts fs" and mediaresize

 

 .fs {
            font-size: x-large !Important;
        }

       @media only screen and (min-device-width: 770px) {
            body {
                overflow: hidden !important;
            }

            .mediaresize {
                font-size: 1.4vw !important;
            }
        }

        @media only screen and (min-device-width: 1200px) {
            body {
                overflow: hidden !important;
                font-size: 1.4vw !important;
                font-family: Arial !important;
            }

            .mediaresize {
                font-size: 1.4vw !important;
                font-family: Arial !important;
            }
        }

 

<header class="site-navbar js-sticky-header site-navbar-target" role="banner" style="background-color: Transparent !important;">
            <div class="container-fluid">
                <div class="row align-items-center position-relative" style="background-color: Transparent !important;">
                    <div class="row-cols-12">
                        <nav class="site-navigation text-right ml-auto kf" role="navigation" style="background-color: Transparent;">
                            <ul class="site-menu main-menu js-clone-nav ml-auto d-none d-lg-inline-flex">
                                <li class="has-children">
                                    <a href="#about-section" class="nav-link fs mediaresize"><em class="icon-import_contacts fs" style="margin-right: 5px;"></em>Import</a>

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Results 1 - 5 of 9
KasimA
 
on Jul 26, 2022 12:43 AM

I am working on it. I will get back to you in one hour.

KasimA
 
on Jul 26, 2022 02:47 AM

Hi kevinf,

Set runat server attribute in the Anchor link. So that you can access Anchor Tag in code behind.

Then set the InnerHtml property.

HTML

<a id="lnkImport" runat="server" href="#about-section" class="nav-link fs mediaresize">
    <em class="icon-import_contacts fs" style="margin-right: 5px;"></em>Import</a>
<asp:Button Text="Set" runat="server" OnClick="OnSet" />

Code

C#

protected void OnSet(object sender, EventArgs e)
{
    lnkImport.InnerHtml = "<em class='icon-import_contacts fs' style='margin-right: 5px;'></em>Export";   
}

VB.Net

Protected Sub OnSet(sender As Object, e As EventArgs)
    lnkImport.InnerHtml = "<em class='icon-import_contacts fs' style='margin-right: 5px;'></em>Export"
End Sub

Screenshot

kevinf
 
on Jul 26, 2022 03:28 AM
on Jul 26, 2022 03:32 AM

Thanks but it wasn't was my question or I don't understand

I currently use If textdesc = "textblack" or "textm" etc in a label called lFound and add the Attributes.Add("Class", textdesc) to set the lFount text color

textdesc could by Red, Black, Green etc how do I use this to change the Text Import in my menus's from black to the color stored in textdesc

I have multiple menu items Students Maintenance reporting etc all need text color to be changed see below

 

 </em>Import</a>

 

}
.textm {
    color: #FFCCFF !important;
}
.textn {
    color: #00CC66 !important;
}
.texto {
    color: Aqua !important;
}
.textblack {
    color: Black !important;
}

 

 <a href="#about-section" class="nav-link fs mediaresize"><em class="icon-graduation-cap fs" style="margin-right: 5px;"></em>Student(s)</a>
 <ul class="dropdown dropdown arrow-top" style="width: 240px">
 <li><a href="SLSS.aspx">Master</a></li>
 <li><a href="SLSN.aspx">Note</a></li>
 <li><a href="SLSD.aspx">Error Deletion</a></li>
 </ul>
 </li>
 
 <li class="has-children">
 <a href="#about-section" class="nav-link fs mediaresize"><em class="icon-wrench fs" style="margin-right: 5px;"></em>Maintenance</a>
 <ul class="dropdown dropdown arrow-top" style="width: 280px">
 <li><a href="SLP.aspx">Personalise</a></li>
 <li><a href="SLC.aspx">Maintenance</a></li>
 <li><a href="SLR.aspx">Control</a></li>
 <li><a href="SLS.aspx">Note Entry</a></li>
 </ul>
 </li>

 

dharmendr
 
on Jul 26, 2022 04:56 AM

Share the code you are using to set the Attribute.

kevinf
 
on Jul 26, 2022 06:13 PM

If I use your code the color texte (White) changes on the class='icon-import_contacts texte fs' but doesn't change the </em>Import</a>

I would like to change the text for all of the menu headings

If textdesc = "" Then textdesc = "textblack"

lFound.Attributes.Add("Class", textdesc)
lSchool.Attributes.Add("Class", textdesc)
cbAll.Attributes.Add("Class", textdesc)

FontChange.InnerHtml = "<a id='FontChange' runat='server' href='#about-section' class='nav-link texte fs mediaresize'><em class='icon-import_contacts texte fs' style='margin-right: 5px;'></em>Import</a>"

Menu

Results 1 - 5 of 9