Showing posts with label event. Show all posts
Showing posts with label event. Show all posts

Saturday, March 31, 2012

Strange behavior with server web controls

Hi,

I don't know if anybody else experienced this, but sometimes, I can't set
breakpoints the event code of a button on a form for some reason. The code
still executes, but I can't stop the execution with a breakpoint. While
compiling, a question mark appears in the red dot on the left side of the
code editor and if I hover my mouse over it, it says

"The breakpoint will not currently be hit. No executable code is associated
with this line."

The last time I experienced this, I has to copy the event code somewhere
else, delete the form button and recreate it by pasting the code back.
Anybody had this happen to them? Is there an explanation?

Thanks

EricJust an idea...

Sometimes, VS.NET would erase everything after the Handles clause. Perhaps you
could see if that's the case.

I'm just speculating that the compiler is noticing that without a handler,
there's nothing to call the code.

Ken

"news.public.microsoft.com" <mindmover@.hotmail.com> wrote in message
news:eIU3lNWUDHA.372@.tk2msftngp13.phx.gbl...
Hi,

I don't know if anybody else experienced this, but sometimes, I can't set
breakpoints the event code of a button on a form for some reason. The code
still executes, but I can't stop the execution with a breakpoint. While
compiling, a question mark appears in the red dot on the left side of the
code editor and if I hover my mouse over it, it says

"The breakpoint will not currently be hit. No executable code is associated
with this line."

The last time I experienced this, I has to copy the event code somewhere
else, delete the form button and recreate it by pasting the code back.
Anybody had this happen to them? Is there an explanation?

Thanks

Eric

Saturday, March 24, 2012

Strange Event Behavior


Scenario:

Class A has a method that returns an instantiated object of Class B.

Class A has a Public Event called "DataUpdated".

When the Class A method is called to return an instance of Class B,
Class A hands to Class B a pointer to itself. Therefore, Class B can
reference the instance of Class A that instantiated it.

Thus, Class B can call the DataUpdated event on the instance of Class A
that instantied it. A method of Class A marked "Friend", called
OnDataUpdated, is called when the "Save" method of Class B is called.

Weirdness:
This all works as planned, but strangely. In an ASP.NET application,
I'm storing an instance of Class A in the Cache. When I call the "Save"
method on Class B, the event bubbles up to the instance of Class A as
expected. However, the event fires up to five times. I've stepped
through the code; the event is only raised once.

Any ideas? Thanks.

Dave Swersky

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Is it a special needs class?
Try giving them a longer recess. It will allow them to expend some energy
before they return to your classroom.

Strange event behavior with check boxes

I've designed a gridview that contains a template field with an
unbound checkbox, allowing the user to select certain rows for further
action.
I am capturing the CheckedChanged event in order to set the grid's
SelectedIndex equal to the row whose check box was checked or
unchecked. However, for some strange reason when I click a checkbox
the CheckedChanged event fires for every checked checkbox in the grid,
from top to bottom. Consequently, the SelectedIndex always ends up
being the last checked row.
Can anyone shed some light on this behavior?
-- HansOn Jul 26, 9:23 pm, Froefel <hansdeschry...@.gmail.com> wrote:
> I've designed a gridview that contains a template field with an
> unbound checkbox, allowing the user to select certain rows for further
> action.
> I am capturing the CheckedChanged event in order to set the grid's
> SelectedIndex equal to the row whose check box was checked or
> unchecked. However, for some strange reason when I click a checkbox
> the CheckedChanged event fires for every checked checkbox in the grid,
> from top to bottom. Consequently, the SelectedIndex always ends up
> being the last checked row.
> Can anyone shed some light on this behavior?
> -- Hans
Hi...
can you please provide some code sample...
Masudur

strange event postback behaviour in dynamically created usercontrol

hi,
i have an aspx page which dynamically loads a user control and adds it
to a placeholder. the control is recreated and added to the
placeholder for postbacks as well.
the user control contains a datagrid and some buttons and textboxes.
the button events fire correctly and execute their code. however, the
datagrid events fire a postback, and execute Page_load in the
usercontrol, but the Item_Command code is not executed. the code to
add events to the datagrid is in InitialiseComponent.

i have the datagrid binding in UserControl_PreRender, so that it is
bound between postbacks.

can anyone suggest why the postback is happening without the
ItemCommand event happening? i've verified this with VS debugging.

thanks
timHi Tim_Mac,

Welcome to ASP.NET newsgroup.
From your description, you've a UserControl which contains some button and
a DataGrid on it, the datagrid is subscribing some postback
events(ItemCommand). And in one of your asp.net page, you dynamically load
the usercontrol and add it on your page. However, you found the ItemCommand
of the datagrid(in usercontrol) always not fire, yes?

Based on my experience, such event handler not executing problem is likely
caused by the following things:
1. For dynamic loaded(created) controls, make sure we add them in the
Page_Init or Page_Load every time the page is requested(IsPostback or
not...).

2. For control's event handler, we also need to register them in Init or
Load event. Also, for template databound controls such as DataGrid or
DataList, we should avoid rebinding them with different datasource before
processing postback event since the event may depend on the original binded
datas.

As for your condition, since some other controls (such as button)'s event
handler execute correctly. I think the problem is likely within the
UserControl itself. Would you try registering your datagrid's ItemCommand
handler in the usercontrol's ascx template instead of programmatically
register in codebehind? Just like
<asp:datagrid ..... OnItemCommand="DataGrid_ItemCommand" ...
If you feel it convenient, I suggest you try build a simpler usercontrol
(contains a datagrid) so as to repro the problem and send it to me. Then I
can do some researchs on my side.

In addition, if you feel necessary, I can also generate a test page on my
side and let you have a compare to see whehter there are any difference.

Please feel free to let me know if you have any questions. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
hi Steven,
thank you for your most helpful reply.
i have got it working now, and will attempt to explain how and why for
future reference.

my aspx page contaings the following in Page_Load:
Modules.SportsLadder ladder =
this.LoadControl("Modules/SportsLadder.ascx") as Modules.SportsLadder;
this.serverForm.Controls.Add(ladder);

the user control is loaded regardless of whether a postback has taken
place or not.
the user control then contains a call to if(!IsPostBack) BindGrid() in
the Page_Load.

when i would delete an item in the datagrid, the page would post back,
and Page_Load would fire, but the datagrid_itemcommand event would not
fire. the datagrid would disappear from the page.

i tried adding in a PreRender event for the usercontrol, and calling
BindGrid() there, and that kept the datagrid on screen after postbacks,
but the itemcommand event still didn't fire. what got it working was i
removed the if(!IsPostBack) from the Page_Load of the user control, so
then the datagrid is bound every time. i then had the problem of the
itemcommand event being called twice (what a surprise). the reason is
because it was set in the aspx page, as Steven suggested:
<asp:datagrid ..... OnItemCommand="DataGrid_ItemCommand" ...>
but it was also set in InitialiseComponent in code. i took it out of
the code, and let the aspx handler do it.

now it works perfectly. i didn't run into any problems re-binding the
datagrid in Page_Load, my methods were still able to identify the row
that was clicked and any of the controls in the cells.

thanks for your help.
tim

strange event postback behaviour in dynamically created usercontrol

hi,
i have an aspx page which dynamically loads a user control and adds it
to a placeholder. the control is recreated and added to the
placeholder for postbacks as well.
the user control contains a datagrid and some buttons and textboxes.
the button events fire correctly and execute their code. however, the
datagrid events fire a postback, and execute Page_load in the
usercontrol, but the Item_Command code is not executed. the code to
add events to the datagrid is in InitialiseComponent.
i have the datagrid binding in UserControl_PreRender, so that it is
bound between postbacks.
can anyone suggest why the postback is happening without the
ItemCommand event happening? i've verified this with VS debugging.
thanks
timHi Tim_Mac,
Welcome to ASP.NET newsgroup.
From your description, you've a UserControl which contains some button and
a DataGrid on it, the datagrid is subscribing some postback
events(ItemCommand). And in one of your asp.net page, you dynamically load
the usercontrol and add it on your page. However, you found the ItemCommand
of the datagrid(in usercontrol) always not fire, yes?
Based on my experience, such event handler not executing problem is likely
caused by the following things:
1. For dynamic loaded(created) controls, make sure we add them in the
Page_Init or Page_Load every time the page is requested(IsPostback or
not...).
2. For control's event handler, we also need to register them in Init or
Load event. Also, for template databound controls such as DataGrid or
DataList, we should avoid rebinding them with different datasource before
processing postback event since the event may depend on the original binded
datas.
As for your condition, since some other controls (such as button)'s event
handler execute correctly. I think the problem is likely within the
UserControl itself. Would you try registering your datagrid's ItemCommand
handler in the usercontrol's ascx template instead of programmatically
register in codebehind? Just like
<asp:datagrid ..... OnItemCommand="DataGrid_ItemCommand" ...>
If you feel it convenient, I suggest you try build a simpler usercontrol
(contains a datagrid) so as to repro the problem and send it to me. Then I
can do some researchs on my side.
In addition, if you feel necessary, I can also generate a test page on my
side and let you have a compare to see whehter there are any difference.
Please feel free to let me know if you have any questions. Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
hi Steven,
thank you for your most helpful reply.
i have got it working now, and will attempt to explain how and why for
future reference.
my aspx page contaings the following in Page_Load:
Modules.SportsLadder ladder =
this.LoadControl("Modules/SportsLadder.ascx") as Modules.SportsLadder;
this.serverForm.Controls.Add(ladder);
the user control is loaded regardless of whether a postback has taken
place or not.
the user control then contains a call to if(!IsPostBack) BindGrid() in
the Page_Load.
when i would delete an item in the datagrid, the page would post back,
and Page_Load would fire, but the datagrid_itemcommand event would not
fire. the datagrid would disappear from the page.
i tried adding in a PreRender event for the usercontrol, and calling
BindGrid() there, and that kept the datagrid on screen after postbacks,
but the itemcommand event still didn't fire. what got it working was i
removed the if(!IsPostBack) from the Page_Load of the user control, so
then the datagrid is bound every time. i then had the problem of the
itemcommand event being called twice (what a surprise). the reason is
because it was set in the aspx page, as Steven suggested:
<asp:datagrid ..... OnItemCommand="DataGrid_ItemCommand" ...>
but it was also set in InitialiseComponent in code. i took it out of
the code, and let the aspx handler do it.
now it works perfectly. i didn't run into any problems re-binding the
datagrid in Page_Load, my methods were still able to identify the row
that was clicked and any of the controls in the cells.
thanks for your help.
tim
Hi Tim_Mac,
Thanks a lot for your detailed response. I'm glat that you've got greate
progress on this issue. Though you've got it worked currently, I'm still
abit confusing about your detailed page and usercontrol's code logic. Based
on my understanding, as long as your UserControl is added into the page's
control collection everytime( and has a fixed it assigned to it). We don't
need to bind data to the datagrid(in the usercontrol) everytime, just in
If(! IsPostback) ) or in a postback event is ok. And the ItemCommand can
also fire correctly.
I've attached a sample page/usercontrol I used to test. You can have a test
on your side if you have interesting.
Hope helps. If there is anything else unclear, please feel free to post
here. Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Thursday, March 22, 2012

Strange firing sequence??

Hi all. Can't explain this...
I am using custom control COCA that includes an Image IMAGO. IMAGO raises
the Click event for COCA when clicked. All good so far.
The custom control COCA is created dynamically and lives on a Webform1.
Whenever COCA is clicked, the COCA_Clicked event on Webform1 needs to fire
and return the coordinates values of COCA to a textbox on the form (done via
VB: AddHandler CC1.Click, AddressOf CC1_Clicked).
Here's the confusing part: when CC1 is clicked on the form the first thing
that happens is the page posts back. Only then, CC1_Clicked fires, and
writes value to the textbox. I see CC1_Clicked running by settping through
and the values ARE being written to the textbox but they never actually show
up on the form because they are written after the postback. A second click
causes a postback, writes out the previous values, runs CC1_Clicked... so
the output on the form is always 1 phase behind.
Scratching my head... shouldn't this be the other way around?
Click >> CC1_Clicked fires >> writes values to textbox >> page postback?
The custom control:
- Implements INamingContainer
- adds the ImageButton control in CreateChildControls()
- Overrides the Render method and uses EnsureChildControls()
- Is added to the webform with: Me.FindControl("form1").Controls.Add(CC1)
Any ideas? Suggestions? Corrections?
Thanks. Assaf.Sorry folks: spellchecker out of control.
COCA = CC1
IMAGO = IMG1
"Assaf" <at@.isp.com> wrote in message
news:%23jh5xwwPEHA.648@.TK2MSFTNGP10.phx.gbl...
> Hi all. Can't explain this...
> I am using custom control COCA that includes an Image IMAGO. IMAGO raises
> the Click event for COCA when clicked. All good so far.
> The custom control COCA is created dynamically and lives on a Webform1.
> Whenever COCA is clicked, the COCA_Clicked event on Webform1 needs to fire
> and return the coordinates values of COCA to a textbox on the form (done
via
> VB: AddHandler CC1.Click, AddressOf CC1_Clicked).
> Here's the confusing part: when CC1 is clicked on the form the first thing
> that happens is the page posts back. Only then, CC1_Clicked fires, and
> writes value to the textbox. I see CC1_Clicked running by settping through
> and the values ARE being written to the textbox but they never actually
show
> up on the form because they are written after the postback. A second click
> causes a postback, writes out the previous values, runs CC1_Clicked... so
> the output on the form is always 1 phase behind.
> Scratching my head... shouldn't this be the other way around?
> Click >> CC1_Clicked fires >> writes values to textbox >> page postback?
> The custom control:
> - Implements INamingContainer
> - adds the ImageButton control in CreateChildControls()
> - Overrides the Render method and uses EnsureChildControls()
> - Is added to the webform with: Me.FindControl("form1").Controls.Add(CC1)
> Any ideas? Suggestions? Corrections?
> Thanks. Assaf.
>

Strange firing sequence??

Hi all. Can't explain this...

I am using custom control COCA that includes an Image IMAGO. IMAGO raises
the Click event for COCA when clicked. All good so far.

The custom control COCA is created dynamically and lives on a Webform1.
Whenever COCA is clicked, the COCA_Clicked event on Webform1 needs to fire
and return the coordinates values of COCA to a textbox on the form (done via
VB: AddHandler CC1.Click, AddressOf CC1_Clicked).

Here's the confusing part: when CC1 is clicked on the form the first thing
that happens is the page posts back. Only then, CC1_Clicked fires, and
writes value to the textbox. I see CC1_Clicked running by settping through
and the values ARE being written to the textbox but they never actually show
up on the form because they are written after the postback. A second click
causes a postback, writes out the previous values, runs CC1_Clicked... so
the output on the form is always 1 phase behind.

Scratching my head... shouldn't this be the other way around?
Click >> CC1_Clicked fires >> writes values to textbox >> page postback?

The custom control:
- Implements INamingContainer
- adds the ImageButton control in CreateChildControls()
- Overrides the Render method and uses EnsureChildControls()
- Is added to the webform with: Me.FindControl("form1").Controls.Add(CC1)

Any ideas? Suggestions? Corrections?

Thanks. Assaf.Sorry folks: spellchecker out of control.
COCA = CC1
IMAGO = IMG1

"Assaf" <at@.isp.com> wrote in message
news:%23jh5xwwPEHA.648@.TK2MSFTNGP10.phx.gbl...
> Hi all. Can't explain this...
> I am using custom control COCA that includes an Image IMAGO. IMAGO raises
> the Click event for COCA when clicked. All good so far.
> The custom control COCA is created dynamically and lives on a Webform1.
> Whenever COCA is clicked, the COCA_Clicked event on Webform1 needs to fire
> and return the coordinates values of COCA to a textbox on the form (done
via
> VB: AddHandler CC1.Click, AddressOf CC1_Clicked).
> Here's the confusing part: when CC1 is clicked on the form the first thing
> that happens is the page posts back. Only then, CC1_Clicked fires, and
> writes value to the textbox. I see CC1_Clicked running by settping through
> and the values ARE being written to the textbox but they never actually
show
> up on the form because they are written after the postback. A second click
> causes a postback, writes out the previous values, runs CC1_Clicked... so
> the output on the form is always 1 phase behind.
> Scratching my head... shouldn't this be the other way around?
> Click >> CC1_Clicked fires >> writes values to textbox >> page postback?
> The custom control:
> - Implements INamingContainer
> - adds the ImageButton control in CreateChildControls()
> - Overrides the Render method and uses EnsureChildControls()
> - Is added to the webform with: Me.FindControl("form1").Controls.Add(CC1)
> Any ideas? Suggestions? Corrections?
> Thanks. Assaf.