Solved

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

Posted on 2011-02-16
11
612 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:bidgadget
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:bidgadget
Comment Utility
Much appreciated. Thank you for the lesson.

0
 

Author Comment

by:bidgadget
Comment Utility
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
Comment Utility
Can you paste your VB code where you check user login and the name of your hyperlink onClick method
0
 

Author Comment

by:bidgadget
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

9 Experts available now in Live!

Get 1:1 Help Now