We help IT Professionals succeed at work.

Create redirect link in code behind

kdeutsch
kdeutsch used Ask the Experts™
on
I am trying to create a redirect link in my code behind.  If the data row I am pulling end up blank I want it to put in the field "NOT SET'  (DONE)  if there is something I want it to list out what is in data rows (DONE).  The next portion is I want to turn it into a redirect link so that if someone click on the words above it redirect them to another page to set some further values, below is my code but I cant seem to get it correct.


sql = "Select strBenchmarkName from tblBenchmarkname where intSid = " & myDataTable.Rows(0)(1) & " order by strBenchmarkname"

                BmTable = New DataTable
                BmTable = getData(sql)

                If BmTable.Rows.Count = 0 Then
                    bmName = ""
                Else
                    For Each bmrow In BmTable.Rows
                        bmName += bmrow(0) & ", "
                    Next

                    bmName = Left(bmName, Len(bmName) - 2)
                End If

                If isAdmin = True Then
                    If bmName = "" Then
                        bmName = "(not set)"
                    End If

                    lblBMName.Text = "<div style='display:inline;cursor:hand;' onclick='window.location.replace('EditMetric.aspx?sid=' + myDataTable.Rows(0)(1)&kpname=myDataTable.Rows(0)(1)); & bmName & "</div>"
                Else
                     lblBMName.Text = "<div style='display:inline;cursor:hand;' onclick='window.location.replace('EditMetric.aspx?sid=' + myDataTable.Rows(0)(1)&kpname=myDataTable.Rows(0)(1)); & bmName & "</div>"
                End If

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Ok, sorry worng stuff, here is what is needed, but I need to get the words in there and another value to pass to the queury string so last part of code should look liek this but with additions of other values and it should go right to page no opening another page.


 If isAdmin = True Then
                    If bmName = "" Then
                        bmName = "(not set)"
                    End If

                    lblBMName.Text = "<a onclick='javascript:window.open(""EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) & """, """", ""fullscreen=yes scrollbars=yes"");' " _
                         & "style='text-decoration:underline;cursor:hand;'>"
                Else
                    lblBMName.Text = "<a onclick='javascript:window.open(""EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) & """, """", ""fullscreen=yes scrollbars=yes"");' " _
                        & "style='text-decoration:underline;cursor:hand;'>"
                End If

Open in new window

Try just making your label an anchor tag like this:

lblBMName.Text = "<div style='display:inline;cursor:hand;> <A HREF='EditMetric.aspx?sid='" & myDataTable.Rows(0)(1) & "kpname=" & myDataTable.Rows(0)(1) & bmName & "> Whatever text you want visible </a></div>"

Author

Commented:
Ok got to this point but it will not recognize my second variable and the text of the data before it.  

 lblBMName.Text = "<a onclick='javascript:window.open(""EditMetric.aspx?sid=" & myDataTable.Rows(0)(1)&kpName=& myDataTable.Rows(0)(0)""", """", ""fullscreen=yes scrollbars=yes"");' " _
                         & "style='text-decoration:underline;cursor:hand;+ bmname'>"
                Else
                    lblBMName.Text = bmName + "<a onclick='javascript:window.open(""EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) &&kpName=& myDataTable.Rows(0)(0) """, """", ""fullscreen=yes scrollbars=yes"");' " _
                        & "style='text-decoration:underline;cursor:hand;+ bmname'>"

Author

Commented:
propakmike,
For some reason If I make a div tag it messes up my whole screen for some reason, need to change to a onclick event or a straight A href that redir4ects to another page automatically.


 lblBMName.Text = "<a onclick='javascript:window.open(""EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) & "kpName="& myDataTable.Rows(0)(0)"""", """"", ""fullscreen=yes scrollbars=yes"");' " _
                    & "style='text-decoration:underline;cursor:hand;+ bmname'>"
You can place your div tag on your aspx designer page right before the label.

Author

Commented:
propakmike:,
Sorry not a javascript guy or one whom uses divs alot, is there a way to make it a onclick event from the code behind that you can click on that text and pass the 2 variables to next page.

Author

Commented:
This seems to be what I want to do but I need the second variable in here to work and then it opens in a wierd window I just need it to open in same window to new site.

 lblBMName.Text = bmName + "<a onclick='javascript:window.open(""EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) & "kpName=& myDataTable.Rows(0)(0) """", """", ""fullscreen=yes scrollbars=yes"");' " _
                    & "style='text-decoration:underline;cursor:hand;+ bmname'>"
You have set the bmName  value inside the style property of hyperlink tag. Place it inner Text of hyperlink tag.
So in the last line, instead of  
& "style='text-decoration:underline;cursor:hand;+ bmname'>"
change it as
& "style='text-decoration:underline;cursor:hand; ' > & bmname & "</a>"
Change the text to have the Ampersands in the link.
EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) & "&kpName="& myDataTable.Rows(0)(0)

Author

Commented:
All,
Ok its worksing with passing the correct data, but still cant get the right text in there and it opens in a really goofy window with no resizable tools, is there a way to use a redirect with this method.

lblBMName.Text = "<a onclick='javascript:window.open(""EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) & "&kpName=" & myDataTable.Rows(0)(0) & """, """", ""fullscreen=yes scrollbars=yes"");' " _
                         & "style='text-decoration:underline;cursor:hand;'> & bmname & "

name in text box cmoes up with &bmname &  instead of what should be Not Set or what was in the label from data row per code above.
Take out the javascript onclick and make it an "HREF=" then within the a tag set the target='_new' and it will open as a new window.

<a HREF="EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) & "&kpName=" & myDataTable.Rows(0)(0) & """, """", ""fullscreen=yes scrollbars=yes"");' " _
                         & "style='text-decoration:underline;cursor:hand;' target='_new'>

Author

Commented:
I get an error that says end of statement expected.

 lblBMName.Text = bmName + "<a HREF="EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) & "&kpName=" & myDataTable.Rows(0)(0) & """, """", ""fullscreen=yes scrollbars=yes"");' " _
                         & "style='text-decoration:underline;cursor:hand;' target='_new'>"
lblBMName.Text = bmName + "<a HREF='EditMetric.aspx?sid=" &  myDataTable.Rows(0)(1) & "&kpName=" & myDataTable.Rows(0)(0) & "style='text-decoration:underline;cursor:hand;' target='_new'>"

Author

Commented:
propakmike:,
Sorry for being a pain.

Ok, getting closer this is how the link works in the browser, how do i drop off the style out of it.  and the text looks like this  test1, tst2, test3_  the only part that is a onclikc is the underscore, cannot pick on rest of text.

http://localhost:1336/StratPlan/EditMetric.aspx?sid=9124&kpName=15style=


 lblBMName.Text = bmName + "<a HREF='EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) & "&kpName=" & pNum & "style='text-decoration:underline;cursor:hand;' target='_new'>"
lblBMName.Text =  "<a HREF='EditMetric.aspx?sid=" &  myDataTable.Rows(0)(1) & "&kpName=" & pNum target='_new'>" & bmName & "</a>"

Author

Commented:
propakmike:
I get an end of statement expected and a blue underline for everything after the PNum.

target='_new'>" & bmName & "</a>"

Author

Commented:
propakmike:
ok I did this and it took care of the name problem and the name is now a link, but the loiink still passes with like this. I just need up to the 15 part.
http://localhost:1336/StratPlan/EditMetric.aspx?sid=9124&kpName=15target=

I put in a & but then that put the style back in the query string.
 lblBMName.Text = "<a HREF='EditMetric.aspx?sid=" & myDataTable.Rows(0)(1) & "&kpName=" & pNum & "target='_new'>" & bmName & "</a>"
Remove unwanted text   "target='_new'

Use like following:

 lblBMName.Text = "<a HREF='EditMetric.aspx?sid=" &  myDataTable.Rows(0)(1) & "&kpName=" & pNum &  " '>" & bmName & "</a>"

Author

Commented:
karthitron:
thanks it worked and opend in a redirected full window.

Author

Commented:
Thanks for patience, and lots of help.