Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Strange Issue on replacing Image control with ImageButton control

Reply
Thread Tools

Strange Issue on replacing Image control with ImageButton control

 
 
jens.buchta@gmx.net
Guest
Posts: n/a
 
      09-01-2005
Hi!

I'm using a DataGrid with a template column to display an Image inside
of it. I'm hooking into its OnPrerender-Event to set the
ImageURL-Property dynamically.
Everything works just fine here, until I thought "It would be cool, if
the user could click on that image..". So I replaced the Image-Control
with an ImageButton.

My Problem is, that the ImageButton doesn't fire any events. Any other
control works just fine but I'm having no luck getting the ImageButton
to work.

I'm happy about any ideas..

Regards
Jens


------------------------------------------------
Code-Snippet

-------------------
aspx-Page

<asp:TemplateColumn HeaderText="Images">
<ItemTemplate>
<asp:Image id="imgPic" runat="server"
OnPreRender="imgPic_PreRender"></asp:Image>&nbsp;
<asp:ImageButton id="ibtnPic" runat="server"
OnPreRender="ibtnPic_PreRender"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>

-------------------
CodeBehind

protected void imgPic_PreRender(object sender, System.EventArgs e)
{
//this works as expected
Image img = sender as Image;
if (img == null)
{
return;
}
img.ImageURL = "dynamically-assigned.jpg";
}

protected void ibtnPic_PreRender(object sender, System.EventArgs e)
{
//this does not work
//
//if I rename this Method for testing purposes, the Page can't
//be loaded, as it doesn't find this Method
//
//if I set a Break-Point to first method, the program does not
//stop
ImageButton ibtn = sender as ImageButton;
if (ibtn == null)
{
return;
}
ibtn.ImageURL = "dynamically-assigned.jpg";
}

 
Reply With Quote
 
 
 
 
jens.buchta@gmx.net
Guest
Posts: n/a
 
      09-01-2005
Thanks for your Answer!

I can set up the Click event to parse the CommandName and
CommandArgument. This is a way to react on the users PostBack, no
problem here.

The problem is, that i need the PreRender event to handle the ImageURL
before the ImageButton is drawn. At the moment, I can't catch this
event in the same way, as it works for the Image-control, so that the
image, the ImageButtons renders, is "none".

Jens

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      09-01-2005
Jens,

With thwe ImageButton you can setup both the Click and Command events. Do
you setup one of them?

Eliyahu

<> wrote in message
news: ups.com...
> Hi!
>
> I'm using a DataGrid with a template column to display an Image inside
> of it. I'm hooking into its OnPrerender-Event to set the
> ImageURL-Property dynamically.
> Everything works just fine here, until I thought "It would be cool, if
> the user could click on that image..". So I replaced the Image-Control
> with an ImageButton.
>
> My Problem is, that the ImageButton doesn't fire any events. Any other
> control works just fine but I'm having no luck getting the ImageButton
> to work.
>
> I'm happy about any ideas..
>
> Regards
> Jens
>
>
> ------------------------------------------------
> Code-Snippet
>
> -------------------
> aspx-Page
>
> <asp:TemplateColumn HeaderText="Images">
> <ItemTemplate>
> <asp:Image id="imgPic" runat="server"
> OnPreRender="imgPic_PreRender"></asp:Image>&nbsp;
> <asp:ImageButton id="ibtnPic" runat="server"
> OnPreRender="ibtnPic_PreRender"></asp:ImageButton>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> -------------------
> CodeBehind
>
> protected void imgPic_PreRender(object sender, System.EventArgs e)
> {
> //this works as expected
> Image img = sender as Image;
> if (img == null)
> {
> return;
> }
> img.ImageURL = "dynamically-assigned.jpg";
> }
>
> protected void ibtnPic_PreRender(object sender, System.EventArgs e)
> {
> //this does not work
> //
> //if I rename this Method for testing purposes, the Page can't
> //be loaded, as it doesn't find this Method
> //
> //if I set a Break-Point to first method, the program does not
> //stop
> ImageButton ibtn = sender as ImageButton;
> if (ibtn == null)
> {
> return;
> }
> ibtn.ImageURL = "dynamically-assigned.jpg";
> }
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      09-01-2005
Why can't you handle the ImageUrl in Click event?

Eliyahu

<> wrote in message
news: ups.com...
> Thanks for your Answer!
>
> I can set up the Click event to parse the CommandName and
> CommandArgument. This is a way to react on the users PostBack, no
> problem here.
>
> The problem is, that i need the PreRender event to handle the ImageURL
> before the ImageButton is drawn. At the moment, I can't catch this
> event in the same way, as it works for the Image-control, so that the
> image, the ImageButtons renders, is "none".
>
> Jens
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange issue with ImageButton with no ImageUrl Gary K ASP .Net 2 01-08-2008 05:20 PM
Replacing - and not Replacing... Rob Meade ASP General 5 04-11-2005 06:49 PM
How to keep aspect ratio of image inside an ImageButton control? Arthur Hsu ASP .Net 5 12-08-2004 12:51 AM
image/imagebutton control Jason ASP .Net Web Controls 0 06-13-2004 02:38 AM
SQL image (jpeg) to Image or ImageButton or TableRow etc.. RobertH ASP .Net 3 02-17-2004 02:39 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57