Solved

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

Posted on 2011-02-16
11
624 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now