Amit Kumar

Amit Kumar

  • NA
  • 140
  • 41.1k

how to change the nevigate url of hyperlink in asp

Dec 2 2013 2:45 AM
this hierarchy of master page
|--main.master
   |-- index.aspx
   |-- user.master
       |-- login.aspx
means master page of user.master is main.master, master page of login page is user.master i have a loginview control on main.master page. code for loginview as
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
                        <AnonymousTemplate>
                            [ <a href="~/PageCommon/login.aspx" id="HeadLoginStatus" runat="server" color="#87cfe6">Log In</a> ]
                        </AnonymousTemplate>
                        <LoggedInTemplate>
                            Welcome <span class="bold">
                                <asp:HyperLink ID="HyperLink1" ForeColor="PeachPuff" Font-Size="Larger" ToolTip="MyHome"  runat="server"> <asp:LoginName ID="HeadLoginName" runat="server" /></asp:HyperLink>
                            </span>&nbsp;&nbsp;
                            [
                            <asp:LoginStatus ID="HeadLoginStatus" ForeColor="#87cfe6" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/PageCommon/index.aspx" />
                            ]
                        </LoggedInTemplate>
                    </asp:LoginView>
now in code behind of login page i want to access the hyperlink of login view to change the nevigate url of that hyperlink . but i am unable to access the hyperlink . i used this code to access the hyperlink
if (User.Identity.IsAuthenticated)
        {
        HyperLink rdirect = (HyperLink)Master.FindControl("HyperLink1");

            int index = utype.SelectedIndex;
            if (index == 0)
            {
                rdirect.NavigateUrl = ResolveUrl("~/PageUser/MyProfile.aspx");

            }
            else if (index == 1)
            {
                rdirect.NavigateUrl = ResolveUrl("~/PageAdmin/MyProfile.aspx");
            }
        }
master page of login page is user.master , and master page for user.master is main.master.


Answers (1)