Re: How to fire an event
- From: "Dave Sexton" <dave@jwa[remove.this]online.com>
- Date: Thu, 9 Nov 2006 23:25:28 -0500
Hi Daniela,
It seems that changing values by code, which is done on client side does not
triger an event. I would need to force a postback. How can it be done?
You should have mentioned that the "code" you spoke of was actually script,
running on the client. I never would have thought that manipulating the grid
in script would cause a server event to be raised.
You can force a post back by dynamically adding the ASP.NET javascript
postback method call to your own client script. This can be done by calling
the GetPostBackEventReference method (Page class in 1.* and Page.ClientScript
in 2.0) on the server to insert the callback into your own script:
<script type="text/javascript">
function doingThings()
{
// do some things in javascript
// post back to raise the button's click event
<%= ClientScript.GetPostBackEventReference(gridControl, string.Empty) %>
}
</script>
The problem here is that I have no idea whether the grid will raise the
UpdateRowBatch event on a post back. What action in particular raises the
UpdateRowBatch event? What argument needs to be supplied, if any? You might
want to read the grid's documentation and figure out what that event is
intended for before trying to raise it yourself.
The alternative to posting back for the grid control is to post back for your
button control (change "gridControl" to "myButton" in the javascript above,
for example) and perform the actions in code, on the server, as I suggested in
my previous response.
If you don't want to use a button then you can postback to the Page (change
"gridControl" to "this" or "Page" in the javascript above) and implement
IPostBackEventHandler.
Of course I can use the code under the event for the button click event, but
the other one would loop thru all the rows automatically.
If you can do so then it will be much easier (and safer) to iterate all of the
rows yourself when the button is pressed than it would be to try to rig the
event to be raised unnaturally.
Please realize that if what you are trying to accomplish has absolutely
nothing to do with the grid's UpdateRowBatch event then you shouldn't be using
the event at all.
--
Dave Sexton
"Daniela Roman" <danielaroman@xxxxxxxxxx> wrote in message
news:e73uiaHBHHA.4428@xxxxxxxxxxxxxxxxxxxxxxx
It seems that changing values by code, which is done on client side does not
triger an event. I would need to force a postback. How can it be done?
Of course I can use the code under the event for the button click event, but
the other one would loop thru all the rows automatically.
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:uFOxT$5AHHA.4060@xxxxxxxxxxxxxxxxxxxxxxx
Hi Daniela,
... and in the mean time, you can possibly solve your problem by placing
the code from the event handler that isn't being called (which you could
call directly anyway) into another method as such:
void gd_UpdateRowBatch(object sender, EventArgs e)
{
CommonMethod();
}
void btn_Click(object sender, EventArgs e)
{
CommonMethod();
}
void CommonMethod()
{
// TODO: something in common
}
If the grid does things that require the event to actually be raised, you
might be able to emulate the effect yourself in the CommonMethod.
GL
--
Dave Sexton
"Daniela Roman" <danielaroman@xxxxxxxxxx> wrote in message
news:emku445AHHA.4568@xxxxxxxxxxxxxxxxxxxxxxx
Thanks. In fact I use a 3-rd party WEB grid control and for some reason it
does not fire the UpdateRowBatch event when I change the values of the
grid thru code. I need to raise that event thru other means.
The sample I provided is not the best example.
Is there another way of firing an event externally?
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:eHN$8z5AHHA.4992@xxxxxxxxxxxxxxxxxxxxxxx
Hi Daniela,
I want to fire the grid's event but I don't know how to call the event
and provide the parameter list for it:
There are many events on the DataGrid control. You just have to perform
an action that will cause the grid to raise the desired event. It's not
common to raise Control events externally; Controls raise their own
events internally.
Are you trying to get the PageIndexChanged event to be raised from your
button click event handler?
If so, change the CurrentPageIndex property and the event should be
raised by the DataGrid.
--
Dave Sexton
"Daniela Roman" <danielaroman@xxxxxxxxxx> wrote in message
news:OOLr774AHHA.4592@xxxxxxxxxxxxxxxxxxxxxxx
Hello,
I try to fire an event under a button click event and maybe anybody can
give a clue please.
I have let's say a WEB grid with PageIndexChanged event:
private void DataGrid1_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
// Set CurrentPageIndex to the page the user clicked.
DataGrid1.CurrentPageIndex = e.NewPageIndex;
// Rebind the data.
DataGrid1.DataBind();
}
Under a button click event:
private void btnUpdtCmd_Click(object sender, System.EventArgs e)
{
}
I want to fire the grid's event but I don't know how to call the event
and provide the parameter list for it:
(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs
e)
Thank you,
Daniela
.
- Follow-Ups:
- Re: How to fire an event
- From: Daniela Roman
- Re: How to fire an event
- References:
- How to fire an event
- From: Daniela Roman
- Re: How to fire an event
- From: Dave Sexton
- Re: How to fire an event
- From: Daniela Roman
- Re: How to fire an event
- From: Dave Sexton
- Re: How to fire an event
- From: Daniela Roman
- How to fire an event
- Prev by Date: Re: Form designer problem - cannot load a form
- Next by Date: Re: what am I doing wrong ?
- Previous by thread: Re: How to fire an event
- Next by thread: Re: How to fire an event
- Index(es):