473,473 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
Create 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 StatementCompleted 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 1254
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
AStatementCompleted 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.ExecuteNonQuery();

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

finally
{ connection.Close(); }
void commandBackup_StatementCompleted(object sender,
StatementCompletedEventArgs e)
{
// retrieving the command object fromn the sender param of the event
SqlCommand commandResult = ((SqlCommand)sender);

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

// retrieve the value of the output parm
string resultString =
commandResult.Parameters["@ResultString"].Value.ToString();

textboxCompleted.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
AStatementCompleted 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.ExecuteNonQuery();

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

finally
{ connection.Close(); }
void commandBackup_StatementCompleted(object sender,
StatementCompletedEventArgs e)
{
// retrieving the command object fromn the sender param of the event
SqlCommand commandResult = ((SqlCommand)sender);

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

// retrieve the value of the output parm
string resultString =
commandResult.Parameters["@ResultString"].Value.ToString();

textboxCompleted.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
AStatementCompleted 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.ExecuteNonQuery();

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

finally
{ connection.Close(); }
void commandBackup_StatementCompleted(object sender,
StatementCompletedEventArgs e)
{
// retrieving the command object fromn the sender param of the event
SqlCommand commandResult = ((SqlCommand)sender);

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

// retrieve the value of the output parm
string resultString =
commandResult.Parameters["@ResultString"].Value.ToString();

textboxCompleted.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
AStatementCompleted 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.Open();
// execute the SP
commandBackup.ExecuteNonQuery();
}
catch (Exception ex)
{ // exception handling here }
finally
{ connection.Close(); }
void commandBackup_StatementCompleted(object sender,
StatementCompletedEventArgs e)
{
// retrieving the command object fromn the sender param of the event
SqlCommand commandResult = ((SqlCommand)sender);
// !! GET ERROR HERE when trying to access the param value

// retrieve the value of the output parm
string resultString =
commandResult.Parameters["@ResultString"].Value.ToString();
textboxCompleted.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
AStatementCompleted 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 #6

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

Similar topics

6
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...
2
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...
1
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...
3
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...
5
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...
9
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...
6
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...
3
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...
2
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
1
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...
0
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.