Link to home
Start Free TrialLog in
Avatar of kdeutsch
kdeutschFlag for United States of America

asked on

Create redirect link in code behind

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

Avatar of kdeutsch
kdeutsch
Flag of United States of America image

ASKER

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>"
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'>"
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.
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.
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)
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.
ASKER CERTIFIED SOLUTION
Avatar of propakmike
propakmike
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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'>"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>"
propakmike:
I get an end of statement expected and a blue underline for everything after the PNum.

target='_new'>" & bmName & "</a>"
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>"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
karthitron:
thanks it worked and opend in a redirected full window.
Thanks for patience, and lots of help.