Thursday, March 29, 2012
Newbie -- Page_Load( ) fires twice if image is added to Login page
I'm using Visual Studio 2005 + ASP.NET and C#
I have a login.aspx page with AutoEventWireup set to FALSE (also added to
top level Web.Config, and set to false)
With a "template" loginCtl the Page_Load( ) event fires once.
As soon as I add an ImageCtl or just drag an image using the designer, onto
the login page and then run it, I'm seeing the Page_Init( ) and Page_Load( )
functions being fired twice.
If I remove the image, then these methods are only fired once.
Any ideas?
I am setting the event delegate like this in my login.aspx.cs file:
protected override void OnInit( EventArgs e )
{
this.Load += new EventHandler( Page_Load );
}
protected void Page_Load( ... etc.
Thanks for any tips,
FrankThis isn't a direct answer, but I personally avoid that this.Load += new
EventHandler(Page_Load) stuff that the wizard puts in like the plague. The
reason being is that I subclass pages a lot, and when you depend on wiring
up events, you can run into issues where a subclass won't call the base
initializer, or the listeners get added in an order that prevents proper
handling (I'd have to dig up an example, but I had issues with Page_Load
never firing at all). Since you're overriding OnInit just to wire up an
event handler, I'd just override OnLoad and see if that might prevent the
double-hit (plus, you're plugging into the vtable instead of having to deal
with event firing/delegate calling)
Newbie -- Page_Load( ) fires twice if image is added to Login page
I'm using Visual Studio 2005 + ASP.NET and C#
I have a login.aspx page with AutoEventWireup set to FALSE (also added to
top level Web.Config, and set to false)
With a "template" loginCtl the Page_Load( ) event fires once.
As soon as I add an ImageCtl or just drag an image using the designer, onto
the login page and then run it, I'm seeing the Page_Init( ) and Page_Load( )
functions being fired twice.
If I remove the image, then these methods are only fired once.
Any ideas?
I am setting the event delegate like this in my login.aspx.cs file:
protected override void OnInit( EventArgs e )
{
this.Load += new EventHandler( Page_Load );
}
protected void Page_Load( ... etc.
Thanks for any tips,
FrankThis isn't a direct answer, but I personally avoid that this.Load += new
EventHandler(Page_Load) stuff that the wizard puts in like the plague. The
reason being is that I subclass pages a lot, and when you depend on wiring
up events, you can run into issues where a subclass won't call the base
initializer, or the listeners get added in an order that prevents proper
handling (I'd have to dig up an example, but I had issues with Page_Load
never firing at all). Since you're overriding OnInit just to wire up an
event handler, I'd just override OnLoad and see if that might prevent the
double-hit (plus, you're plugging into the vtable instead of having to deal
with event firing/delegate calling)
Thursday, March 22, 2012
newbie hyperlink question
Just playing around using the QuickStart site. I placed this code in my code
behind:
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Set hyperlink to "~", which indicates application root.
link1.NavigateUrl = "~"
End Sub
this code in my page:
<asp:hyperlink ID="link1" runat="server">this link test</asp:hyperlink>
The tutorial has me placing the sub in the page itself -- but shouldn't this
work regardless? It displays the text as a link but hovering over it does
nothing.
thanksDo you want the link to go to another page..
What do you want it to do when you hover over it?
Patrick
"thersitz" <thersitz@.gmail.comwrote in message
news:upGZO8sKHHA.4376@.TK2MSFTNGP03.phx.gbl...
Quote:
Originally Posted by
Hi,
>
Just playing around using the QuickStart site. I placed this code in my
code
Quote:
Originally Posted by
behind:
>
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Set hyperlink to "~", which indicates application root.
link1.NavigateUrl = "~"
End Sub
>
this code in my page:
>
<asp:hyperlink ID="link1" runat="server">this link test</asp:hyperlink>
>
The tutorial has me placing the sub in the page itself -- but shouldn't
this
Quote:
Originally Posted by
work regardless? It displays the text as a link but hovering over it does
nothing.
>
thanks
>
>
>
>
>
>
>
Instead of "~" try "~/" for the navigateurl.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"thersitz" <thersitz@.gmail.comwrote in message
news:upGZO8sKHHA.4376@.TK2MSFTNGP03.phx.gbl...
Quote:
Originally Posted by
Hi,
>
Just playing around using the QuickStart site. I placed this code in my
code behind:
>
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Set hyperlink to "~", which indicates application root.
link1.NavigateUrl = "~"
End Sub
>
this code in my page:
>
<asp:hyperlink ID="link1" runat="server">this link test</asp:hyperlink>
>
The tutorial has me placing the sub in the page itself -- but shouldn't
this work regardless? It displays the text as a link but hovering over it
does nothing.
>
thanks
>
>
>
>
>
>
>
thanks.
I originally had the file name -- "default.aspx" as the target -- and a file
by that name in the same directory -- but still the link would not activate
on viewing the page -- the style sheet viewed it as a link and applied the
appropiate style but no link functionality upon hovering over it. I have to
run but will try your suggestion first thing in the morn.
thanks for the response.
"Mark Fitzpatrick" <markfitz@.fitzme.comwrote in message
news:u1HAHXtKHHA.4912@.TK2MSFTNGP02.phx.gbl...
Quote:
Originally Posted by
Instead of "~" try "~/" for the navigateurl.
>
>
--
>
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
>
>
"thersitz" <thersitz@.gmail.comwrote in message
news:upGZO8sKHHA.4376@.TK2MSFTNGP03.phx.gbl...
Quote:
Originally Posted by
>Hi,
>>
>Just playing around using the QuickStart site. I placed this code in my
>code behind:
>>
> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
> ' Set hyperlink to "~", which indicates application root.
> link1.NavigateUrl = "~"
> End Sub
>>
>this code in my page:
>>
><asp:hyperlink ID="link1" runat="server">this link test</asp:hyperlink>
>>
>The tutorial has me placing the sub in the page itself -- but shouldn't
>this work regardless? It displays the text as a link but hovering over it
>does nothing.
>>
>thanks
>>
>>
>>
>>
>>
>>
>>
>
>
Thanks Patrick.
Well, when I hover over it I expected my cursor to change to a hand pointing
cursor and respond as if it were a regular html link and thus allow me to
click and follow the url assigned to it. It does neither. The style sheet
treats it as a link and formats it accordingly. But hovering over it, the
response is the same as hovering over any non-link text.
I have changed the link1,NavigateURL to "default.aspx" with a file so named
in the same directory as the page. I have changed it to "~/" as per another
suggestion made on this thread. And no go.
So I am missing something fairly fundamental. Any ideas. I took this stuff
right off the asp.net tutorial.
"Patrick.O.Ige" <naijacoder@.hotmail.comwrote in message
news:eYk9uStKHHA.5000@.TK2MSFTNGP03.phx.gbl...
Quote:
Originally Posted by
Do you want the link to go to another page..
What do you want it to do when you hover over it?
Patrick
>
"thersitz" <thersitz@.gmail.comwrote in message
news:upGZO8sKHHA.4376@.TK2MSFTNGP03.phx.gbl...
Quote:
Originally Posted by
>Hi,
>>
>Just playing around using the QuickStart site. I placed this code in my
code
Quote:
Originally Posted by
>behind:
>>
> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
> ' Set hyperlink to "~", which indicates application root.
> link1.NavigateUrl = "~"
> End Sub
>>
>this code in my page:
>>
><asp:hyperlink ID="link1" runat="server">this link test</asp:hyperlink>
>>
>The tutorial has me placing the sub in the page itself -- but shouldn't
this
Quote:
Originally Posted by
>work regardless? It displays the text as a link but hovering over it does
>nothing.
>>
>thanks
>>
>>
>>
>>
>>
>>
>>
>
>