views:

22

answers:

2

So, here's the scenario:

I have a page in my asp.net c# based website, which displays data dynamically after taking the request from query strings. For example: Brand=HTC&model=Wildfire

Now, in this page I want to display all the deals available in each network separately. So, on the first pageload, I retrieve the data from the tables of each network that has the requested handset in a deal, store it as a datatable in the cache. I have a datalist for displaying the imagebuttons of the networks that have the deals of that handset. The user will click on the imagebutton of a network to view the deals of that network.

To display the deals, I am using a gridview which retrieves its datasource from the cache. Also, I have provided filtering of the rows through dropdowns in each columns' header of the gridview.

All this is inside an updatepanel.

Everything's working fine.

The Problem: I want that whenever the user clicks a network's image button, an image should appear above the gridview, containing the logo of that network.

Things that I have tried: I am storing the networkname in the cache(which also required for filtering the gridview), whenever an imagebutton is clicked. Then, on pageload, I'm doing this:

if(ScriptManager1.IsInAsyncPostBack)
{
    Image img = new Image();
    img.ImageUrl = "images/" + Cache["network"] + "_logo.jpg";
    nw_image.Controls.Clear();
    nw_image.Controls.Add(img);
}

where, nw_image is a tablecell which i'm using to display the selected network logo. and also I've saved the network logos in the images folder as: 'network'_logo.jpg eg: 3_logo.jpg, orange_logo.jpg

The result of this is that when I click a new image button, the image that is displayed is that of the previous network, i.e. the cache is always one postback late.

Please Help! Thanks!

+1  A: 

Rather than using dynamic controls (i.e. creating the Image control manually on a postback), it would be much easier to just define an Image control in your page markup and default its Visible property to false. Then on your postback, set the ImageUrl property to the correct URL, and the Visible property to true.

Also, ensure that your nw_image table cell is inside your UpdatePanel, and you either have ChildrenAsTriggers set to true on the update panel (this is the default), or have specified an AsyncPostbackTrigger for the Click event of the ImageButton.

Graham Clark
I did try that also(oops, forgot to mention :@), but it didn't work at all, I mean the image wasn't displaying at all. though i'll try it again.The tablecell nw_image nad also the image button is inside the updatepanel.
Anchit
Just tried that static image solution, it still has the same problem as the dynamic image.
Anchit
A: 

At last I've got it to work.

I've now put a static image without any properties except id = "net_img" , runat = "server" and EnableViewState = "true".

And instead of taking the network name from the cache, I'm changing the image in the click event of the ImageButton according to the Imagebutton that is clicked.

And it works now! :)

Anchit