Solved

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

Posted on 2011-02-16
11
627 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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