Showing posts with label imagebutton. Show all posts
Showing posts with label imagebutton. Show all posts

Wednesday, March 28, 2012

Strange bug with textbox.text property

I have this is my page_load

txtSearchTerm.text = "All"

Then I have an imagebutton, when its clicked I want to redirect to a page based on the value of that textbox.

So in my imagebutton click event I have

Response.Redirect("auctions.aspx?search=" + txtSearchTerm.text)

My problem is this text is always "All", even when the user changes the value of the textbox

????

Help !

put you initialize in !IsPostBack

if(!IsPostBack){this.txtSearchTerm.Text="ALL";}

or you can set the default value in the form .aspx file use Text="ALL"


hi,

zeroxp kind of touch it a little, but i want to add something to his reply.

whenever a client click on a button on your webform, asp.net actually will reload itself, then process the Button1_Click event. Therefore, if you want to do something when the page is load, but not everytime it refrashes, use if (!IsPostBack){} or in vb.net: if page.ispostback = false then .

Just want to remind all people out there who maybe thinking this is a bug.. no it isn't... just the way asp.net webform was designed.

Alan,

Thursday, March 22, 2012

Strange Issue on replacing Image control with ImageButton control

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>
<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";
}Jens,

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

Eliyahu

<jens.buchta@.gmx.net> wrote in message
news:1125557636.729770.63420@.g49g2000cwa.googlegro 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>
> <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";
> }
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
Why can't you handle the ImageUrl in Click event?

Eliyahu

<jens.buchta@.gmx.net> wrote in message
news:1125566088.815538.95660@.o13g2000cwo.googlegro 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

Strange issue with ImageButton with no ImageUrl

I realize that there is no good reason for an image button to not have an
ImageUrl but I have just hit upon a strange problem when converting an
ASP.NET 1.1 web application to 2.0. An asp:ImageButton control without an
ImageUrl contained within a WebForm causes a redirect to the default
document in IIS. This behaviour did not occur in .NET 1.1.
This can easily be duplicated by the following steps :-
1. Create a new ASP.NET Web Application project in VS2005.
2. Add a new Web Form (WebForm1.aspx)
3. In the existing Default.aspx add a standard asp:Button to the form and
add a standard on click event handler containing a simple
Response.Redirect("WebForm1.aspx");
4. Add an asp:ImageButton to WebForm1.aspx, e.g <asp:ImageButton
ID="ImageButton1" runat="server" />
5. Set two breakpoints, one on each Page_Load method of both Web Forms.
Debug the application, you will notice it breakpoints on the Default.aspx
page load and on the postback when you press the button. This is fine. It
will then breakpoint on the page load of WebForm1.aspx and *THEN* redirect
back to Default.aspx and break on the page load event again. The final
breakpoint does not occur if the ImageUrl is completed or if no default
document has been setup in IIS.
Thanks
Garythis is standard browser behavior. any img, script, css, etc, with a src="http://pics.10026.com/?src="
or missing, will use the default path as the url. iis will usually redirect
to default.aspx (or whatever is the default).
-- bruce (sqlwork.com)
"Gary K" wrote:

> I realize that there is no good reason for an image button to not have an
> ImageUrl but I have just hit upon a strange problem when converting an
> ASP.NET 1.1 web application to 2.0. An asp:ImageButton control without an
> ImageUrl contained within a WebForm causes a redirect to the default
> document in IIS. This behaviour did not occur in .NET 1.1.
> This can easily be duplicated by the following steps :-
> 1. Create a new ASP.NET Web Application project in VS2005.
> 2. Add a new Web Form (WebForm1.aspx)
> 3. In the existing Default.aspx add a standard asp:Button to the form and
> add a standard on click event handler containing a simple
> Response.Redirect("WebForm1.aspx");
> 4. Add an asp:ImageButton to WebForm1.aspx, e.g <asp:ImageButton
> ID="ImageButton1" runat="server" />
> 5. Set two breakpoints, one on each Page_Load method of both Web Forms.
> Debug the application, you will notice it breakpoints on the Default.aspx
> page load and on the postback when you press the button. This is fine. It
> will then breakpoint on the page load of WebForm1.aspx and *THEN* redirect
> back to Default.aspx and break on the page load event again. The final
> breakpoint does not occur if the ImageUrl is completed or if no default
> document has been setup in IIS.
> Thanks
> Gary
>
>
> this is standard browser behavior. any img, script, css, etc, with a
> src="http://pics.10026.com/?src="
> or missing, will use the default path as the url. iis will usually
> redirect
> to default.aspx (or whatever is the default).
Thanks for the reply Bruce, that does make sense now.
The generated html is different between the versions of Visual Studio, I now
see the src="http://pics.10026.com/?src=" has been added :-
VS2003
<input type="image" name="ImageButton1" id="ImageButton1" alt="" border="0"
/>
VS2005
<input type="image" name="ImageButton1" id="ImageButton1" src="http://pics.10026.com/?src="
style="border-width:0px;" />
That explains it.
Thanks
Gary

Strange Issue on replacing Image control with ImageButton control

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 , 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>
<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";
}Jens,
With thwe ImageButton you can setup both the Click and Command events. Do
you setup one of them?
Eliyahu
<jens.buchta@.gmx.net> wrote in message
news:1125557636.729770.63420@.g49g2000cwa.googlegroups.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 , 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>
> <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";
> }
>
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
Why can't you handle the ImageUrl in Click event?
Eliyahu
<jens.buchta@.gmx.net> wrote in message
news:1125566088.815538.95660@.o13g2000cwo.googlegroups.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
>