locked
store label text value to session then get value (code behind) RRS feed

  • Question

  • User-49671077 posted

    I'm try to store label text value to session then get value code behind when click img1

    Here is the code so far using but nothing.

    Please help!

    <div style="height:220px;overflow:hidden">
    				<img ID="img1" runat="server" class="pointer" src="images/photos/1.jpg" border="0" height="150" alt="My Image" onclick="return img1_onclick()"/>
    
    </div>
    
    <asp:Label ID="Label1_1" runat="server" Font-Bold="True" Font-Size="Small" 
                                            ForeColor="Black" Text="Label"></asp:Label>
    
    
    function img1_onclick() {
            var myVar = document.getElementById('<%=Label1_1.ClientID %>');
            window.location.href = window.location.href.replace(/[\?#].*|$/, "?param=" + myVar);
    
          }
    
    ** Code behind VB) **
    Dim myVar As String = Request.QueryString("param") Session("SessionName") = myVar


    Monday, April 6, 2020 12:20 PM

All replies

  • User475983607 posted

    Your code is very confusing.  The image is already wrapped in an anchor tag.  The browser does an HTTP GET when the image is clicked.  This refreshes the current page.  There is also a JavaScript click handler which does an HTTP GET to an unknown location.

    Please take a few minutes to review your code and perform basic debugging.   If you want community support you'll need to explain how the code is intended to function because the code shown does not make sense.

    Edit: Original Code.

    <div style="height:220px;overflow:hidden">
    <a href="profiledf8e.html?id=4042007;" target="_blank"  class="image">
    	<img ID="img1" runat="server" src="images/photos/1.jpg" border="0" height="150" alt="Free online dating Poland" onclick="return img1_onclick()" />
    </a>
    
    </div>
    
    <asp:Label ID="Label1_1" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black" Text="Label"></asp:Label>
    										
    function img1_onclick() {
            var myVar = document.getElementById('<%=Label1_1.ClientID %>');
            window.location.href = window.location.href.replace(/[\?#].*|$/, "?param=" + myVar);
    
          }
    
    ** Code behind VB) **
    
    Dim myVar As String = Request.QueryString("param")
            Session("SessionName") = myVar

    Monday, April 6, 2020 1:32 PM
  • User-49671077 posted

    Sorry, Code updated

    Monday, April 6, 2020 2:29 PM
  • User475983607 posted

    Sorry, Code updated

    Your new code is not much better.  There's an ending </a>.   The link that warps the image was removed but it is not clear how or when the label is populated or the resulting text value.  As far as the community can tell the label value starts off as "Label".

    My best guess is you have a timing issue but there is not enough code to figure out what you're doing.  Please debug your code.

    Monday, April 6, 2020 2:46 PM
  • User-49671077 posted

    Thanks for your time, yes my mistake after debug I have seen as:

    Dim myVar As String = Request.QueryString("param")
    Session("SessionName") = myVar  >>  [object HTMLSpanElement] 

    image for your reference,  can you advice for another code when image click..

    Monday, April 6, 2020 3:09 PM
  • User475983607 posted

    The sample code is depends on the value of Label1_1.  There is no indication when or how the server control is populated. 

    <asp:Label ID="Label1_1" runat="server" Font-Bold="True" Font-Size="Small" 
    ForeColor="Black" Text="Label"></asp:Label>

    your screenshot looks like you are debugging JavaScript but showing server side code.  Perhaps you think by myVar is the same on both the server and browser.  It is not.  There is one myVar on the server and another in the browser.

    Monday, April 6, 2020 3:43 PM