locked
ImageURL returns empty after loading the image with JQuery RRS feed

  • Question

  • User1356489325 posted

    I have a DataList on my webform, which has ImageButtons. I am loading the images in these ImageButtons using JQuery:

    img.attr("src", photo.find("URL").text());

    I want to get the ImageURL from my VB code when the user clicks on an ImageButton. But all I am getting is an empty string.

    The HTML for the ImageButton is:

    <asp:ImageButton runat="server" ImageUrl='<%#Eval("Url")%>' CssClass="image" OnClick="img_Click" />

    And img_Click function in the code behind:

    Protected Sub img_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim img As ImageButton = TryCast(sender, ImageButton)
        Dim str As String = img.ImageUrl
    End Sub
    Thursday, February 18, 2016 4:37 PM

Answers

  • User61956409 posted

    Hi Arzoo Sana,

    I am loading the images in these ImageButtons using JQuery:

    img.attr("src", photo.find("URL").text());

    I want to get the ImageURL from my VB code when the user clicks on an ImageButton. But all I am getting is an empty string.

    It seems that you dynamically set src property for ImageButton from client side using jQuery and you’d like to get the value of src from code behind when you click the ImageButton. You could try to save the value of photo.find("URL").text() in hidden field, then you could get the value from hidden field on server side code.

    <asp:HiddenField ID="hfimgsrc" runat="server" Value="" />
    img.attr("src", photo.find("URL").text());
    $("#hfimgsrc").val(photo.find("URL").text());
    //...
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 19, 2016 5:44 AM

All replies

  • User753101303 posted

    Hi,

     ASP.NET doesn't know anything about the change you have done using jQuery (only form fields are posted back to the web server).

    Not sure what is your goal. If this is to find which button is clicked and/or on which row, you could use for example the CommandName and/or CommandArgument properties. See https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandname(v=vs.110).aspx or explain your final goal so that one can suggest another approach.

    Thursday, February 18, 2016 4:56 PM
  • User1356489325 posted

    I want to check which ImageButton was clicked so that I can enlarge that image. And I did try using CommandArgument, but that comes back empty too.

    Thursday, February 18, 2016 5:01 PM
  • User753101303 posted

    And how do you define CommandArgument?

    Anyway for now it doesn't seems you need to really go back to the server but that doing client side would be enough. Not sure what is the exact effect you want but you could change for example the height/width/padding of the image (to enlarge it while preserving the rest of the layout).

    Or do you mean showing another version in a popup or something like that?

    Thursday, February 18, 2016 5:12 PM
  • User61956409 posted

    Hi Arzoo Sana,

    I am loading the images in these ImageButtons using JQuery:

    img.attr("src", photo.find("URL").text());

    I want to get the ImageURL from my VB code when the user clicks on an ImageButton. But all I am getting is an empty string.

    It seems that you dynamically set src property for ImageButton from client side using jQuery and you’d like to get the value of src from code behind when you click the ImageButton. You could try to save the value of photo.find("URL").text() in hidden field, then you could get the value from hidden field on server side code.

    <asp:HiddenField ID="hfimgsrc" runat="server" Value="" />
    img.attr("src", photo.find("URL").text());
    $("#hfimgsrc").val(photo.find("URL").text());
    //...
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 19, 2016 5:44 AM