Solved

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

Posted on 2011-02-16
11
630 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:bidgadget
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 10

Expert Comment

by:himanshut
ID: 34912556
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
 

Author Comment

by:bidgadget
ID: 34912624
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
 
LVL 10

Accepted Solution

by:
himanshut earned 500 total points
ID: 34912653
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:bidgadget
ID: 34912732
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
 
LVL 10

Expert Comment

by:himanshut
ID: 34912790
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
 

Author Comment

by:bidgadget
ID: 34912805
Much appreciated. Thank you for the lesson.

0
 

Author Comment

by:bidgadget
ID: 34913153
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
 
LVL 10

Expert Comment

by:himanshut
ID: 34913294
Can you paste your VB code where you check user login and the name of your hyperlink onClick method
0
 

Author Comment

by:bidgadget
ID: 34913330
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
 
LVL 10

Expert Comment

by:himanshut
ID: 34913340
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
 

Author Comment

by:bidgadget
ID: 34913353
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

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question