Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid - Linkbutton Redirect Function

Status
Not open for further replies.

tickko

Programmer
Dec 12, 2002
25
0
0
US
I'm sure that this is possible, just can't seem to get it to work. Within a ASP.Net page I have a datagrid. Within that datagrid I want to redirect the user to an edit page, sending the 'index' key along with the address using javascript.


I've successfully opened a new window with a querystring with no problems.

(Code Behind) - ItemBoundData Sub
Code:
If e.Item.Cells(0).Controls.Count > 0 Then ' Edit Link
     If TypeOf (e.Item.Cells(0).Controls(0)) Is LinkButton Then
          Dim btnView As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
          btnView.Attributes("onclick") = "OpenForm('Viewer.aspx?var0=" & e.Item.Cells(1).Text & "','width=800,height=600,resizable=yes,scrollbars=yes');"
     End If
End If

(Javascript)
Code:
     <script language="javascript" type="text/javascript">
           function OpenForm(strURL,strFeatures)
           {
               window.open(strURL,'',strFeatures);
           }
     </script>

This works great, the only problem is that I don't want it to open a new window, rather redirect to a new page within the same window.

Heres my last attempt at openning in the same window:

(Code Behind) - ItemBoundData Sub
Code:
If e.Item.Cells(0).Controls.Count > 0 Then ' View Link
     If TypeOf (e.Item.Cells(0).Controls(0)) Is LinkButton Then
          Dim btnView As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
          btnView.Attributes("onclick") = "RedirectForm('Viewer.aspx?var0=" & e.Item.Cells(1).Text & "');"
     End If
End If

(Javascript)
Code:
     <script language="javascript" type="text/javascript">
           function RedirectForm(strURL)
           {
               window.location=strURL;
           }
     </script>


What I'm doing wrong I couldn't tell you, please help...
Thanks,
t
 
Answered my own question...

Instead of using js to redirect the page, I should be using the datagrids 'ItemCommand' sub. By including it in the 'BehindCode', I also have the ability to pass session variables along with it.

Code:
     If e.Item.Cells(0).Controls.Count > 0 Then ' Edit Link
          If TypeOf (e.Item.Cells(0).Controls(0)) Is LinkButton Then
          Response.Redirect("EditRec.aspx?var0=" & e.Item.Cells(1).Text)
          End If
     End If

But if anyone knows if the first post is possible, I would like to know. Just from the stand-point that its good to know.

Regards,
t
 
this is what i use for javascript redirect

<script language="javascript" type="text/javascript">
function RedirectForm(strURL)
{
window.location.href=strURL;
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top