Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return image or image url from the handler?

Status
Not open for further replies.

Technokrat

Programmer
Jul 20, 2001
92
0
0
US
I have a datagrid with a templated field that looks like the following:

Code:
<asp:TemplateField HeaderText="Sunday">
            <ItemTemplate>
        <asp:Image ID="Image1" runat="server" 
            ImageUrl='<%# "AvailabilityButtonHandler.ashx?EmployeeId=1&DOW=0&ID=" + Eval("Sunday")%>' />    
            </ItemTemplate>
            </asp:TemplateField>

In the handler, it runs a query to see if the employee is available, or unavailable for work and the desired result should be the display of the proper image

Code:
            if((Int32)cmd.ExecuteScalar() != 0)
                context.Response.Write("icoUnAvailable.png");
            else
                context.Response.Write("icoAvailable.png");

This isn't working. Is there a way to return the image URL from the handler, or do I have to load and display the image from within the handler?
 
You'll have to write the actual image out in the handler, not just a string containing the filename. Depending on how you will and where you are retrieving your image from, it could be something like:
Code:
Response.ContentType = "image/png"           Response.BinaryWrite(myImageByteArray)

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Thank you, that worked.

However, clicking one of the dynamic buttons causes a postback/repaint of all the buttons in the grid. The desired result would be a change in state of the clicked button and not a refresh of the whole page.

I tried putting "return false;" in the OnClientClick, but this stops the change in state of the clicked button.

This lead me to try using an OnClientClick of "button_click(this);return false;" this gives me a jscript object expected error, however clicking to ignore the error proceeds and gives me the desired change in state of the button without the repaint of the whole grid... Any ideas???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top