skip to Main Content

i have a webapplication in .net and use a DetailsView.
im control this DetailsView with a SqlDataSource. i set a session with jquery.

     <script >
         var baseUrl = (window.location).href;
         var clubid = baseUrl.substring(baseUrl.lastIndexOf('=') + 1);
         sessionStorage.setItem("se", "13801");
         var ses = sessionStorage.getItem("se");
     </script>

Fields of DetailsView :

<Fields>
    <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
    <asp:BoundField DataField="name" HeaderText="name"
        SortExpression="name" />
    <asp:BoundField DataField="saltasis" HeaderText="saltasis" SortExpression="saltasis" />
    <asp:CommandField />
    <asp:CommandField ShowEditButton="True" />
    <asp:CommandField ShowInsertButton="True" />
    <asp:CommandField ShowDeleteButton="True" />
</Fields>

and SQLDATASOURCEID :

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sina1ConnectionString %>" 
    SelectCommand="SELECT * FROM [club] WHERE saltasis = @saltasis">
    <SelectParameters>
    <asp:SessionParameter Name="?" SessionField="?" Type="string" />
    </SelectParameters>

</asp:SqlDataSource>

how to use a session as a value in SelectCommand of SqlDataSource for DetailsView.

2

Answers


  1. Store session value in hidden field with javascript. Pay attention, if you use the master page, the name of the hidden field is as follows:

    document.getElementById('ContentPlaceHolder1_hiddenfield1').value = "session_value";
    

    Then you can use the session value stored in the hidden field

    Login or Signup to reply.
  2. Hi in your example i only show you save the session value inside your sessionStorage but you didn’t past inside a html form or ajax as POST or GET. So you need to catch the url inside your controller: for example this URL (window.location).href
    https://domain.eg/ControllerName/ActionName?se=13801

    [httpGet]
    public void ActionName(string se)
    

    {

      var sessionParams = se;
      -- do what you want with that...
    

    }

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search