1

ASP.NET 2.0 framework

I'm trying to list all user related entries when the user visits the page. I have a session variable set with the visitor in session. Now I want to query the database with that ID. It seems to be executing, but no results are being returned (I'm displaying the contents in a seperate code section).

Please help!

<asp:SqlDataSource
ID="UserReports" 
runat="server"
ConnectionString= "<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand = "SELECT [ID], [ReportName], [ReportPath] FROM [Pan].          
[dbo].[Reports] WHERE ([VisitorID] = @VisitorID)"
OnSelecting  = "SqldsExample_Selecting">

<SelectParameters>
    <asp:Parameter Name="VisitorID" Type="String"/>
</SelectParameters>    
</asp:SqlDataSource>

On the code behind:

Sub SqldsExample_Selecting(sender As Object, e As      
SqlDataSourceSelectingEventArgs)

UserReports.SelectParameters.Add("@VisitorID", Session("VisitorID"))

End Sub
Kana
  • 13
  • 5

1 Answers1

2

Don't use <asp:Parameter>.You should be using <asp:SessionParameter> to access the session variable directly:

<SelectParameters>
    <asp:SessionParameter Name="VisitorID" SessionField="VisitorID" />
</SelectParameters> 
Denys Wessels
  • 16,829
  • 14
  • 80
  • 120
  • Thanks Dennis. With your suggestion, I'm getting the following: Compiler Error Message: BC31143: Method 'Protected Sub SqlDataSource1_Selected(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)' does not have a signature compatible with delegate 'Delegate Sub SqlDataSourceSelectingEventHandler(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)'. – Kana Jul 09 '16 at 23:50
  • Remove the Selecting event handler completely.Set the session in the page load or on the previous page and access it using the example I provided.Have a look at this example - http://forums.asp.net/t/1062765.aspx?sqldatasource+using+session+data+in+select+parameters.Do it exactly the way ecbruck suggests – Denys Wessels Jul 10 '16 at 05:42
  • Thanks Dennis. Removed the Selecting event handler completely. And the session is being set on the pageLoad. Session("VisitorID") = userID Now getting: Parser Error Message: The server tag is not well formed. Source Error: Line 15: – Kana Jul 10 '16 at 11:13
  • That means one of the controls in your .aspx page is not well formed(doesn't have a closing tag,has an invalid character e.t.c) inspect your .aspx page and find the problem.And remember to mark my post as answered if it helped you – Denys Wessels Jul 10 '16 at 11:37
  • Thank you Denis. I was able to get the parse error corrected and now able to see the results with the following: The reason I had Selecting event handler was because I wanted to track the user clicks on the links above. Can you please help? – Kana Jul 10 '16 at 18:30
  • Thank you for your directions Denis -I managed to get the most. I'm currently having an issue when users click on those links (using LinkButtons), if the URL is a web page, all goes well. But when the URL underneth the LinkButton is URL that's directly linked to an .xlsx, I get the "405 - HTTP verb used to access this page is not allowed."...any thoughts? I expect to have a 'Save As' window to appear when such links are clicked...Please advise. – Kana Jul 10 '16 at 20:19
  • I'm using – Kana Jul 10 '16 at 20:22
  • Please mark as answered if my answer helped you and ask a new question on stackoverflow rearding your other problem and someone will help you – Denys Wessels Jul 11 '16 at 04:12