hyperlink column with session variable

6 posts, 1 answers
  1. TSCGlobal
    TSCGlobal avatar
    43 posts
    Member since:
    Jan 2008

    Posted 16 Mar 2010 Link to this post

    I have a project in which one column is a hyperlink column.  Ideally, when the user clicks on the hyperlink, three things happen:

    1. The row the hyperlink is in is selected
    2. The data in the hyperlink column is passed to a session variable
    3. A new browser window opens up, and the session variable is passed to the new page in that separate window.

    Currently, it appears that the only thing that is taking place is that a new browser window opens up, in spite of the fact that I have the appropriate code in the SelectedIndexChanged event that would pass the data into the session variable.  I hope someone can help me with this, or perhaps suggest a more efficient way of accomplishing this task.  Here is the relevant code:

    the .aspx:
    <telerik:RadGrid ID="rgPoOrders" runat="server" DataSourceID="dsPurchaseOrders"   
        GridLines="None">  
        <MasterTableView ItemStyle-HorizontalAlign="Center" AutoGenerateColumns="False" Width="95%"   
        DataKeyNames="cpono" DataSourceID="dsPurchaseOrders" GridLines="Horizontal" AlternatingItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">  
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px" /> 
            </RowIndicatorColumn> 
              
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px" /> 
            </ExpandCollapseColumn> 
              
            <Columns> 
                <telerik:GridBoundColumn DataField="cpono" HeaderText="PO #" ReadOnly="True"   
                    SortExpression="cpono" UniqueName="cpono">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="DateOnly" DataType="System.DateTime"   
                    HeaderText="Date Submitted" SortExpression="DateOnly" UniqueName="DateOnly">  
                </telerik:GridBoundColumn> 
                <telerik:GridHyperLinkColumn DataTextField="cshortrmk" HeaderText="Tracking #"   
                    Target="_blank" UniqueName="cshortrmk" NavigateUrl="UpsTrack.aspx">  
                </telerik:GridHyperLinkColumn> 
            </Columns> 
              
            <ItemStyle HorizontalAlign="Center" /> 
            <AlternatingItemStyle HorizontalAlign="Center" /> 
            <HeaderStyle HorizontalAlign="Center" /> 
    </MasterTableView> 
    </telerik:RadGrid> 
     
    <asp:ObjectDataSource ID="dsPurchaseOrders" runat="server"   
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"   
        TypeName="OrderEntryTableAdapters.POSelectCommandTableAdapter">  
        <SelectParameters> 
            <asp:SessionParameter Name="FName" SessionField="FName" Type="String" /> 
            <asp:SessionParameter Name="LName" SessionField="LName" Type="String" /> 
        </SelectParameters> 
    </asp:ObjectDataSource> 

    And here's the codebehind:
        Protected Sub rgPoOrders_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs) Handles rgPoOrders.SelectedIndexChanged  
     
            Dim TrackNum As String 
            Dim selectedItem As GridDataItem = rgPoOrders.SelectedItems(0)  
     
            TrackNum = selectedItem(rgPoOrders.MasterTableView.Columns(3)).Text  
            Session.Add("TrackNum", TrackNum)  
            test.Text = TrackNum  
     
        End Sub 
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 16 Mar 2010 Link to this post

    The reason your current setup doesn't work is because it's just a link. It doesn't perform any postback, thus the reason it doesn't raise the SelectedIndexChanged event.

    I would suggest using a GridTemplateColumn and add a LinkButton to it with the CommandName set to Select. This way the row the link is in will be selected and then you could retrieve the value you want from the SelectedIndexChanged event. The only thing you'll need to do is create a popup window using Javascript that sends the user to the link you want. You can accomplish this by assigning the Javascript method to the OnClientClick event of the LinkButton control.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. TSCGlobal
    TSCGlobal avatar
    43 posts
    Member since:
    Jan 2008

    Posted 16 Mar 2010 Link to this post

    That does help a bit.  However I am not very familiar with javascript.  Could you provide some quick code to handle the popup, and where to put it?
  5. Answer
    robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 17 Mar 2010 Link to this post

    So you would create a GridTemplateColumn like so:

    <telerik:GridTemplateColumn> 
                        <ItemTemplate> 
                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="CommandName" OnClientClick="OpenPopupWindow()"></asp:LinkButton> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 

    I setup the OnClientClick property to the javascript below:

    <script type="text/javascript"
    function OpenPopupWindow()  
    window.open("<%=Page.ResolveUrl("~/UpsTrack.aspx")%>"); 
    </script> 

    In the javascript function I'm using the ResolveUrl function to return the full path to the page.

    I hope that helps.
  6. Mark Galbreath
    Mark Galbreath avatar
    171 posts
    Member since:
    Jul 2009

    Posted 17 Mar 2010 Link to this post

    You can also use the url format option of the gridhyperlink API:

    DataNavigateUrlFormatString = "list_LIN_detail.aspx?lin={0}&prevPage=LIN List" 

    You can do almost anything when a user clicks on a hyperlink now.

    Cheers!
    Mark
  7. ra ma
    ra ma avatar
    1 posts
    Member since:
    Nov 2009

    Posted 12 May 2010 Link to this post

    how to set DataNavigateUrlFormatString value at client side(javascript)....
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017