Add controls and save their value RRS feed

  • Question

  • User1920964052 posted


    I stored some images directly in my database. At the moment I am displaying the images in a GridView that includes an select link in each row. I want that behavior: If I click on the select link, a new image control should be created and the image url shall be set to the my image handler including the image ID to display the image.

    Because of the stateless web site I have to recreate each image control. I save already the number of images in the view state. But how can I recreate the image controls with the correct image url? I have to save it, but how/where? I cannot create a new variable in the view state for each image, could I?

    thank you very much for your help!

    Saturday, December 22, 2012 1:34 PM


All replies

  • User1123702521 posted

    I guess, I can't fully understand your situation.. but about viewstates surely you can.. you just have to devise a mechanism to name viewstate variables.. Here I suggest an approach.. append the grid RowIndex with viewstate name to uniquely identify viewstate variable for each row.

    ViewState["myPhoto" + GridView1.SelectedRow.RowIndex.ToString()]= "your value";


    Wednesday, December 26, 2012 8:57 AM
  • User1920964052 posted


    thank you for your answer.

    See the following situation: I have a gridview, filled with images out of the database. When I click select, a new Image control is created in an update panel. The imageurl refers to imagehandler.ashx?ID=x. Because of the async post back of the update panel, I have to recreate all existing image controls + the new image control. That means, in this case all images are pulled out of the database again. And I want to reduce this traffic. Is it possible?

    Hopefully it was clear now. It is a little bit difficult to describe in a few sentence and more difficult to understand. Sorry about this! :)


    Wednesday, December 26, 2012 7:48 PM
  • User-861818263 posted

    you can show that image in POPUP(Model window). 

    1) First put one div outside of Update panel.

    2)Add one image (html) control in div.

    3) Just call one javascript function on click of Link

    4)Assign image url in image control.

    5)Show model window.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 27, 2012 12:47 AM