Link to home
Start Free TrialLog in
Avatar of Darebear
Darebear

asked on

Change hyperlink NavigateURL

Hello.

When a user logs in I'm trying to change a Hyperlink NavigateURL based on their role. The code seems to work and the values get assigned to the hyperlink control if I debug the code but the actual Hyperlink on the page does not get refreshed. The hypelink and login control is is on my master page. How can I redraw or refresh the link?

 Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn
        If Roles.IsUserInRole(Login1.UserName, "Role1") Then
            HyperLinkAdmin.NavigateUrl = "page1.aspx"
            HyperLinkAdmin.Text = "Admin Role 1"
         End If
        If Roles.IsUserInRole(Login1.UserName, "Role2") Then
            HyperLinkAdmin.NavigateUrl = "page2.aspx"
            HyperLinkAdmin.Text = "Admin Role 2"
           
        End If
SOLUTION
Avatar of P_Ramprathap
P_Ramprathap
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Darebear
Darebear

ASKER

Oddly enough that gives me a nullreferenc error. And yet Hyperlink.navigationURL = "page1.aspx" has no problems. If I debug and watch the HyperLinkAdmin control its found no problem and I can see the properties and all the other properties on the control.

I think it's a matter of refreshing the control or redrawing it on the page so it becomes underlined and a valid hyperlink.
are you using any ajax panel ?
Nope, however it doesn't work if I do that either. I even placed the login control in the update panel also and that didn't work. I noticed also the hyperlink control isn't available in the trigger collection for the update panel. I tried also adding the login control to the update panel trigger collection and that didn't help either.

Does you Update panel has triggers?
By default, any postback control inside an UpdatePanel control causes an asynchronous postback and refreshes the panel's content. However, you can also configure other controls on the page to refresh an UpdatePanel control. You do this by defining a trigger for the UpdatePanel control. A trigger is a binding that specifies which postback control and event cause a panel to update. When the specified event of the trigger control is raised (for example, a button's Click event), the update panel is refreshed.  

 <asp:UpdatePanel ID="UpdatePanel1" 
                     UpdateMode="Conditional"
                     runat="server">
                     <Triggers>
                       <asp:AsyncPostBackTrigger ControlID="<YourlogincontrolID>" />
                     </Triggers>
                    ......
                    .....
                    ...
                    ..
                    .
    </asp:UpdatePanel>

Open in new window

Ramprathap, that's what I was saying in my last comment. I added the login control to the Asynchronous postback and it didn't refresh the link.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Aswer posted