Conditional Hyperlink in ASP.net 4 vb platform using visual studio

I am using a membership site in ASP.net

I have already validated the users and need to create a hyperlink on the page the authenicated uses go to.  The hyperlink will be conditional based on eiter the userid or role.

Basically if userA is logged in and selects the hyperlink he will go to pageA and if userB is logged in the same hyperlink will go to PageB

Thank you for any help you can give me.
bidgadgetAsked:
Who is Participating?
 
himanshutConnect With a Mentor Commented:
if you view your aspx page in designer mode where you see the skeleton layout of your controls, Just double click on hyperlink and it will take you to code behind by creating the function hyperlink1_click(object sender, EventArgs e) automatically

there will not be any button as the user will get redirect accordingly, by clicking the hyperlink itself.

Cheers!
0
 
himanshutCommented:
In your aspx page, add an event for Hyperlink OnClick="whatever_name"

In your code behind, in the body of whatever_name(object sender, EventArgs e)
{
 If(user =="userA")
  {
     Response.Redirect("sample.aspx");
  }
  else if(user == "userB")
  {
     Response.Redirect("SampleB.aspx");
   }
   else
    {
       Response.Redirect("index.aspx"); //this will take them to index page if the user is not userA or userB
     }
}



Cheers!
0
 
bidgadgetAuthor Commented:
AWhen you say whatever name. Do you mean a button that I will add ?

Thank you for your response and please forgive my lack of experience.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
bidgadgetAuthor Commented:
Last question.  When i double click on the hyperlink it does not bring me to on click.  Can you please explain how to

add an event for Hyperlink OnClick="whatever_name"

Thanks again.  I assume once I add the event I will be able to get to where you said I would be
0
 
himanshutCommented:
alright,
even the simpler way:

when you are viewing the designer mode of your aspx( not the HTML code), just select the control by clicking once and go to the properties window ->>  You'll see "yellow lightening symbol" click that symbol --> it will take you to events --> you'll see CLICK event, just double click the empty text box next to that CLICK --> it will take you to code behind with that event definition

Hope that works :)
0
 
bidgadgetAuthor Commented:
Much appreciated. Thank you for the lesson.

0
 
bidgadgetAuthor Commented:
I am still having trouble.  Looks like the code you gave me is not vb.  Would you have it in vb.  Also when I click on the lightning bolt the click is not a option for the hyperlink and also it does not recognize user

thank you
0
 
himanshutCommented:
Can you paste your VB code where you check user login and the name of your hyperlink onClick method
0
 
bidgadgetAuthor Commented:
I ended up putting it on a button but still not working.  I am not sure if I am supposed to use session(userid)

thanks again
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Session("UserID") = Nothing Then
            Response.Redirect("Default.aspx")

        Else
            Response.Redirect("default2.aspx")
        End If
    End Sub

Open in new window

0
 
himanshutCommented:
and how do you differenciate amongst users I mean what's the business rule for UserA,userB?
according to your code above, if Session is empty or null ir will redirect to Default.aspx but whats the values that you need to check for redirect.

In other words,  if Session("UserId") is not empty, what value does it contain?
0
 
bidgadgetAuthor Commented:
Sorry.  I was trying different things.  The code I meant to send is attached.  Here I only have one user but I will add more.  When I click it takes me to default2 even if the user Rick is logged in.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Session("UserID") = "Rick" Then
            Response.Redirect("Default.aspx")

        Else
            Response.Redirect("default2.aspx")
        End If
    End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.