Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Events & postbacks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ant - 25 Mar 2008 10:17 GMT
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
Michael Nemtsev [MVP] - 25 Mar 2008 12:25 GMT
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

A> Hi,
A>
A> I am using a sqlCommand object to run a SP. The SP returns an output
A> parameter that I retrieve the value of, & display. I want to use the
A> StatementCompleted event of the command obj. to handle this output
A> param through the sender object after the command completes.
A>
A> When I try to access this sender object (cast to a command object) &
A> then
A> reference the output parm, I get an error:
A> "Object reference not set to an object"
A> indicating that the command object has probably lost its reference in
A> the
A> post back.
A> How can I handle an event over a Postback?
A>
A> Many thanks for any help on this. I'm really stuck Ant
A>
Ant - 26 Mar 2008 01:44 GMT
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;
   }

> Hello Ant,
>
[quoted text clipped - 25 lines]
> A> Many thanks for any help on this. I'm really stuck Ant
> A>
bruce barker - 26 Mar 2008 04:33 GMT
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)

> Hi Michael,
> I haven't included the command object set up but I have given it an OP param
[quoted text clipped - 64 lines]
>> A> Many thanks for any help on this. I'm really stuck Ant
>> A>
Ant - 26 Mar 2008 05:05 GMT
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

> 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.
[quoted text clipped - 74 lines]
> >> A> Many thanks for any help on this. I'm really stuck Ant
> >> A>
Michael Nemtsev [MVP] - 26 Mar 2008 07:30 GMT
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

A> Hi Bruce,
A>
A> Thanks very much for clarifying that for me. Is this something that
A> is not normally done in ASP.NET? (The use of ADO related events)
A>
A> If it is, how could this be done
A>
A> Many thanks
A>
A> Ant
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.
[quoted text clipped - 77 lines]
>>>> A> Many thanks for any help on this. I'm really stuck Ant
>>>> A>

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.