Thursday, March 22, 2012
Strange issue with ImageButton with no ImageUrl
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 label quirk upon a postback
Have a page page1.aspx that has a label1 with text properties set say arial with font size of "large" there is a button on Page1.asp that upon its click event triggers javascript to open another window Page2.aspx. This causes a postback to occur on Page1.aspx as Page2.aspx is opened. If I dismiss Page2.aspx label1 on Page1.aspx has changed to a much larger font that previously set??? Now if I delete lable1 and place another label on the Page1 form and do not set any font properties the issue does not occur ...the font, it remains unchanged. Seems in a labels default mode, when first dragged on a webform the font properties are not set...at least this seems apparently so when viewing them in the properties window.
Anyone have any ideas...strange behaviour that seems to have no apparent answer...yet
Thanks
So you're saying the label's styling changes afterpostback? Is there another class or some style attribute beingassigned to the label, or something (like a span or table) thatsurrounds the label?
Ifwe could see the page in action, we might have a better idea of what'sgoing on; have you tried View Source to see if anything looks differentin the HTML?
As far as I beleive, check the style sheet. You might be applying dynamic style to that particular label. Try changing the name of the label and execute the same code.