473,756 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Events & postbacks

Hi,

I am using a sqlCommand object to run a SP. The SP returns an output
parameter that I retrieve the value of, & display.
I want to use the StatementComple ted event of the command obj. to handle
this output param through the sender object after the command completes.

When I try to access this sender object (cast to a command object) & then
reference the output parm, I get an error:
"Object reference not set to an object"
indicating that the command object has probably lost its reference in the
post back.

How can I handle an event over a Postback?

Many thanks for any help on this. I'm really stuck
Ant

Mar 25 '08 #1
5 1267
Hello Ant,

Could your show the short but working code demonstrating the problem?

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
AHi,
A>
AI am using a sqlCommand object to run a SP. The SP returns an output
Aparameter that I retrieve the value of, & display. I want to use the
AStatementCompl eted event of the command obj. to handle this output
Aparam through the sender object after the command completes.
A>
AWhen I try to access this sender object (cast to a command object) &
Athen
Areference the output parm, I get an error:
A"Object reference not set to an object"
Aindicating that the command object has probably lost its reference in
Athe
Apost back.
AHow can I handle an event over a Postback?
A>
AMany thanks for any help on this. I'm really stuck Ant
A>
Mar 25 '08 #2
Hi Michael,
I haven't included the command object set up but I have given it an OP param
& tested it by not using a statement complete event & it returns a value fine
after ExecuteNonQuery . It's only when I try to retrieve it in the event
handler via the event object (as below) that I get the error.

Thanks very much for helping out here

Ant

try
{
connection.Open ();

// execute the SP
commandBackup.E xecuteNonQuery( );

}
catch (Exception ex)
{ // exception handling here }

finally
{ connection.Clos e(); }
void commandBackup_S tatementComplet ed(object sender,
StatementComple tedEventArgs e)
{
// retrieving the command object fromn the sender param of the event
SqlCommand commandResult = ((SqlCommand)se nder);

// !! GET ERROR HERE when trying to access the param value

// retrieve the value of the output parm
string resultString =
commandResult.P arameters["@ResultStr ing"].Value.ToString ();

textboxComplete d.Text = resultString;
}


"Michael Nemtsev [MVP]" wrote:
Hello Ant,

Could your show the short but working code demonstrating the problem?

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
AHi,
A>
AI am using a sqlCommand object to run a SP. The SP returns an output
Aparameter that I retrieve the value of, & display. I want to use the
AStatementCompl eted event of the command obj. to handle this output
Aparam through the sender object after the command completes.
A>
AWhen I try to access this sender object (cast to a command object) &
Athen
Areference the output parm, I get an error:
A"Object reference not set to an object"
Aindicating that the command object has probably lost its reference in
Athe
Apost back.
AHow can I handle an event over a Postback?
A>
AMany thanks for any help on this. I'm really stuck Ant
A>
Mar 26 '08 #3
if you want to use asynchronous events on a web page, the request has to
wait for the events to finish beofre t can send back the response.
otherwise when the event completes there is no request object.

to handle this asynchronous tasks where added to the page. the page will
wait (but free the thread) for the async tasks to complete before doing
prerender.

-- bruce (sqlwork.com)

Ant wrote:
Hi Michael,
I haven't included the command object set up but I have given it an OP param
& tested it by not using a statement complete event & it returns a value fine
after ExecuteNonQuery . It's only when I try to retrieve it in the event
handler via the event object (as below) that I get the error.

Thanks very much for helping out here

Ant

try
{
connection.Open ();

// execute the SP
commandBackup.E xecuteNonQuery( );

}
catch (Exception ex)
{ // exception handling here }

finally
{ connection.Clos e(); }
void commandBackup_S tatementComplet ed(object sender,
StatementComple tedEventArgs e)
{
// retrieving the command object fromn the sender param of the event
SqlCommand commandResult = ((SqlCommand)se nder);

// !! GET ERROR HERE when trying to access the param value

// retrieve the value of the output parm
string resultString =
commandResult.P arameters["@ResultStr ing"].Value.ToString ();

textboxComplete d.Text = resultString;
}


"Michael Nemtsev [MVP]" wrote:
>Hello Ant,

Could your show the short but working code demonstrating the problem?

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
AHi,
A>
AI am using a sqlCommand object to run a SP. The SP returns an output
Aparameter that I retrieve the value of, & display. I want to use the
AStatementComp leted event of the command obj. to handle this output
Aparam through the sender object after the command completes.
A>
AWhen I try to access this sender object (cast to a command object) &
Athen
Areference the output parm, I get an error:
A"Object reference not set to an object"
Aindicating that the command object has probably lost its reference in
Athe
Apost back.
AHow can I handle an event over a Postback?
A>
AMany thanks for any help on this. I'm really stuck Ant
A>
Mar 26 '08 #4
Hi Bruce,

Thanks very much for clarifying that for me. Is this something that is not
normally done in ASP.NET? (The use of ADO related events)

If it is, how could this be done

Many thanks

Ant

"bruce barker" wrote:
if you want to use asynchronous events on a web page, the request has to
wait for the events to finish beofre t can send back the response.
otherwise when the event completes there is no request object.

to handle this asynchronous tasks where added to the page. the page will
wait (but free the thread) for the async tasks to complete before doing
prerender.

-- bruce (sqlwork.com)

Ant wrote:
Hi Michael,
I haven't included the command object set up but I have given it an OP param
& tested it by not using a statement complete event & it returns a value fine
after ExecuteNonQuery . It's only when I try to retrieve it in the event
handler via the event object (as below) that I get the error.

Thanks very much for helping out here

Ant

try
{
connection.Open ();

// execute the SP
commandBackup.E xecuteNonQuery( );

}
catch (Exception ex)
{ // exception handling here }

finally
{ connection.Clos e(); }
void commandBackup_S tatementComplet ed(object sender,
StatementComple tedEventArgs e)
{
// retrieving the command object fromn the sender param of the event
SqlCommand commandResult = ((SqlCommand)se nder);

// !! GET ERROR HERE when trying to access the param value

// retrieve the value of the output parm
string resultString =
commandResult.P arameters["@ResultStr ing"].Value.ToString ();

textboxComplete d.Text = resultString;
}


"Michael Nemtsev [MVP]" wrote:
Hello Ant,

Could your show the short but working code demonstrating the problem?

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
AHi,
A>
AI am using a sqlCommand object to run a SP. The SP returns an output
Aparameter that I retrieve the value of, & display. I want to use the
AStatementCompl eted event of the command obj. to handle this output
Aparam through the sender object after the command completes.
A>
AWhen I try to access this sender object (cast to a command object) &
Athen
Areference the output parm, I get an error:
A"Object reference not set to an object"
Aindicating that the command object has probably lost its reference in
Athe
Apost back.
AHow can I handle an event over a Postback?
A>
AMany thanks for any help on this. I'm really stuck Ant
A>
Mar 26 '08 #5
Hello Ant,

Keep your results in session or cache
There is no standard way to inform asp.net from the changes on server except
the polling server

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
AHi Bruce,
A>
AThanks very much for clarifying that for me. Is this something that
Ais not normally done in ASP.NET? (The use of ADO related events)
A>
AIf it is, how could this be done
A>
AMany thanks
A>
AAnt
A>
A"bruce barker" wrote:
A>
>if you want to use asynchronous events on a web page, the request has
to wait for the events to finish beofre t can send back the response.
otherwise when the event completes there is no request object.

to handle this asynchronous tasks where added to the page. the page
will wait (but free the thread) for the async tasks to complete
before doing prerender.

-- bruce (sqlwork.com)

Ant wrote:
>>Hi Michael,
I haven't included the command object set up but I have given it an
OP param
& tested it by not using a statement complete event & it returns a
value fine
after ExecuteNonQuery . It's only when I try to retrieve it in the
event
handler via the event object (as below) that I get the error.
Thanks very much for helping out here

Ant

try
{
connection.Op en();
// execute the SP
commandBackup .ExecuteNonQuer y();
}
catch (Exception ex)
{ // exception handling here }
finally
{ connection.Clos e(); }
void commandBackup_S tatementComplet ed(object sender,
StatementComp letedEventArgs e)
{
// retrieving the command object fromn the sender param of the event
SqlCommand commandResult = ((SqlCommand)se nder);
// !! GET ERROR HERE when trying to access the param value

// retrieve the value of the output parm
string resultString =
commandResult .Parameters["@ResultStr ing"].Value.ToString ();
textboxComple ted.Text = resultString;
}
"Michael Nemtsev [MVP]" wrote:

Hello Ant,

Could your show the short but working code demonstrating the
problem?

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog:
http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high
and we miss it, but that it is too low and we reach it" (c)
Michelange lo

AHi,
A>
AI am using a sqlCommand object to run a SP. The SP returns an
output
Aparameter that I retrieve the value of, & display. I want to use
the
AStatementCo mpleted event of the command obj. to handle this
output
Aparam through the sender object after the command completes.
A>
AWhen I try to access this sender object (cast to a command
object) &
Athen
Areference the output parm, I get an error:
A"Object reference not set to an object"
Aindicatin g that the command object has probably lost its
reference in
Athe
Apost back.
AHow can I handle an event over a Postback?
A>
AMany thanks for any help on this. I'm really stuck Ant
A>

Mar 26 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3824
by: V | last post by:
I have found that when I have a composite control that uses the CreateChildControls method, on a regular page load, Page_Load executes before CreateChildControls, but on a postback it is the reverse. This is causing logic problems and it really bothers me that this sequence of events fires inconsistently. Can anyone tell me why this happens and how we might get around it?
2
1240
by: Ralf Müller | last post by:
Hi folks! I'am trying to figure out a way on how to keep my scolling position of the page AND all of it's scrollable divs during postbacks. Sadly it seems that div-scrolling can only be done in conjunction with absolute positioning of the divs which is definitely not what I want. But when using iframes i get multiple aspx-pages and i don't have a clue how to handle events that occur on the page in the iframe on my mainpage. I thought...
1
2103
by: Peter Rilling | last post by:
I have an interesting problem with a datagrid. It is the standard chicken-and-the-egg problem. I have this page with two datagrids. It essentially defines a parent-child relationship. The parent grid has a "edit" and "delete" columns. When the "edit" link button is clicked, I want the child grid to display some information related to the parent. Now the child grid also has some command buttons. My problem is that I cannot get the...
3
1128
by: PJ6 | last post by:
I'm apparently not understanding something. I want to capture some user events in a web control I'm inheriting from, such as a table cell or a button. The code below doesn't work, the attributes aren't even rendered. I'm sure I'm not calling the sub right, either. Can someone clue me in? Paul Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs) Attributes.Add("onMouseOut", "TEST") Attributes.Add("onClick", "TEST")
5
875
by: Ben Dewey | last post by:
This is a repost, But I have some new information. I have a server that is configured for .NET 1.1 and 2.0. For some reason all my postback events for aren't firing when using .NET 1.1. Under IIS in ASP.NET tab, if i switch to 2.0 then the events fire correctly, but my code is not set up for that so i get some random errors. And when i switch back to 1.1 my events still don't fire Anyone know why my post backs are not firing in 1.1?
9
2317
by: Nathan Sokalski | last post by:
I have a very simple UserControl which contains an Image and a Label, which I use to display an image with a caption. I am using this control inside a DataList, setting the two Public variables using attributes in the *.aspx page. Everything displays great for the initial load, but whenever I try to add or delete an item (I have controls to do this on the page), it does not seem to be recieving any values for the public variables. Here is...
6
1756
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost datagrid's OnItemDataBound() method we check for the row in which it's appropriate to add the secondary datagrid. Exactly one row in the topmost grid will contain the secondary grid.
3
1289
by: Steve Hershoff | last post by:
Hi everyone, I'm not sure that what I'm trying can't be done (at least, not how I'm trying to do it) but I was hoping for confirmation and possible suggestions on a future approach. We have created a specialized version of the DropDownList class. An abbreviated version reads like this: public class MyDropDownList: System.Web.UI.WebControls.DropDownList
2
1423
by: =?Utf-8?B?SHV6ZWZh?= | last post by:
Hi, I am using a Multipage control with ASP.Net 1.1. The events for controls within the multipage are not getting fired. Any ideas why this would happen. It was working fine before i added another usercontrol to the page. Thanks
0
10031
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9708
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.