Albert Laure
Albert Laure

Reputation: 1722

Catching a href event in asp.net

So currently here is my code (This is A menu bar that's why i cant use asp link buttons)

  <ul>
                    <li><a href="#"><span>Reconciliation</span></a>
                        <ul>
                            <li><a href="#"><span>Double Entry Per Total Expired</span></a></li>
                            <li><a href="#"><span>Additional Pulled Out Item per Printed SOR</span></a></li>
                            <li><a href="#"><span>Reclassification to proper account</span></a></li>
                            <li><a href="#"><span>Additional ren/red after expiry</span></a></li>
                        </ul>
                    </li>
                    <li><a href="#"><span>Reports</span></a>
                     <ul>
                            <li><a href="ReportPages.aspx"><span>Report Generation</span></a></li>
                            <li><a href="PrendaDEPage.aspx"><span>Upload Prenda</span></a></li>
                            <li><a href="NavFilesPage.aspx"><span>Navision Uploader</span></a></li>
                        </ul>
                    </li>

                    <li><a href="#" class="last"><span>Maintenance</span></a>
                        <ul>
                            <li><a href="UsersMaintenancePage.aspx"><span>Report Matrix</span></a></li>
                            <li><a href="BranchMaintenancePage.aspx"><span>Branches</span></a></li>
                            <li><a href="AuditTrailPage.aspx"><span>Audit Trail</span></a></li>
                        </ul>
                    </li>
                </ul>

i want to add a session variable after i click the <a href> tag but i do not know how to catch the event in asp.net code behind i tried making it runat="Server" but i cannot find any onclick event that i can use for it to work..

Any ideas?

basically the flow i want to achieve is
Click href -> Create a session Variable Session["A"] -> response.redirect to my page.

EDIT: The top part menu with <a href = #> are the ones i need to track and provide a session variable after i click them before i response redirect them into another page. That's why i also used # instead of the name of the page in order to, and hopefully catch the <a href> on click event if there is any.

Upvotes: 0

Views: 2037

Answers (1)

Damith
Damith

Reputation: 63065

change to LinkButton like below

<li><asp:LinkButton ID="MyLink" runat="server" OnClick="MyLink_Click" Text="Double Entry Per Total Expired"></asp:LinkButton></li>

then you can do the rest in the click event

void MyLink_Click(Object sender, EventArgs e) 
{
    Session["A"] = "put some value here";
    Response.Redirect (myURL, false);
}

Anyway if you can't use LinkButton try using onserverclick event like below

<li><a href="#" onserverclick="MyLink_Click"  runat="server" id="MyLink"><span>Double Entry Per Total Expired</span></a></li>

in your code file

void MyLink_Click(Object sender, EventArgs e)
{
    // your code 
}

Upvotes: 2

Related Questions