Showing posts with label postback. Show all posts
Showing posts with label postback. Show all posts

Monday, March 26, 2012

Trouble programatically getting form values on PostBack

I am using the following web controls (list shortened to not bore you!):

protected System.Web.UI.WebControls.RadioButtonList rblSymbols;
protected System.Web.UI.WebControls.CheckBox chkPublish;
protected System.Web.UI.WebControls.DropDownList ddlSubject;
protected System.Web.UI.WebControls.TextBox txtEntry;
protected System.Web.UI.WebControls.Button btnSave;
The btnSave_Click(object sender, System.EventArgs e) is properly registered in the InitializeComponent() method. Inside the btnSave_Click() method, I call another function to save to the db which works fine. However, when I attempt to reference the values of those items, they are not set properly. It's as if the IPostBackDataHandler.LoadPostData() method in the Init of the page lifecycle is not being done at all. Any ideas? So far, I have had to result to the following until this is figured out:
YUCK!:
**********************
myObj.Entry = Request["txtEntry"];
Preferred:
**********************
myObj.Entry = txtEntry.Text;
Thanks in advance for any insight you might have.
--ChadIs it possible you've disabled Viewstate at some point?

Peter,
Yes, itIS possible. In fact, I have done just that on several of my controls. Is this the problem? I will try re-enabling. I have read so much on the pros and cons of keeping it turned on. Is is safe to assume that if I wish to program as described above, I need to keep viewstate enabled?
--Chad

Heh... yeah, that could be the problem :)

ViewState is the mechanism by which your controls' properties are persisted across postbacks. If you want to grab myControl.Text, for example, you must have Viewstate enabled.

On the other hand, if you don't mind grabbing values from the Request.Form collection, you can kill Viewstate with impunity.

Cheers,


Peter - thanks for clearing this up for me! Very helpful!

--Chad

Tuesday, March 13, 2012

Troubleshooting IIS "Hang" / Postback Not Working

I have recently added some code to a web application and now I find it
hanging after I do about 2 or 3 postbacks within the application. It hangs
after
doing different things (I cannot find anything in common) and when I run in
Debug mode, it doesn't even appear to be within my code when it hangs (I put
breakpoints all over the place and it doesn't stop at any of them during the
hang).
It hangs after I click a button on the page... but it never reaches the
Page_Load event of the page it is posting back to.. it is like the PostBack
isn't working.
How do I figure out what is going on? What really confuses me is the fact
that the code works the first time but not the second time I run it.. even
with the exact same input data...
It does seem to be related to uploading images... so I went through my code
and made sure I was disposing of all of the image objects in Finally
statements.
Any thoughts on how I can find the problem?
I have ANTS profiler by Red Gate software and I tried doing a memory profile
but it didn't seem to get me anywhere (either that or I wasn't doing it
right).
It is not causing IIS to crash... just to "spin" for a long time. This is
on my development Win XP Pro machine.
After quite some time, I get the following errors when I debug... but I
think they are more a symptom of the non-response to the application as
opposed to the cause of my problem.
--
A first chance exception of type 'System.Net.Sockets.SocketException'
occurred in system.dll
Additional information: An existing connection was forcibly closed by the
remote host
A first chance exception of type 'System.IO.IOException' occurred in
system.dll
Additional information: Unable to read data from the transport connection.
LoriHi Lori ,
Welcome to ASP.NET newsgroup.
From your description, one of your asp.net always run into hanging after
you do some modification recently. I'm not quite sure what's your orginally
code logic and what's your modification on them. However, have you been
able to isolate the problem to a certain or some certain individule pages?
Also, based on your error message, I think you're doing some network
transfering task , using Socket or httpwebrequest? Generally, if your
server's CPU utilization is not high and application hangs, it's likely
that there are some thread deadlock in your app or there are some longrun
task in your page's exectution steps which block the server's workthreads.
Would provide some further description on your code logic?
In addition, I suggest you turn on the ASP.NET's trace and use Trace.Write
or Warn to output some trace info in the different stage of those page's
execution lifecycle. For example, before page_load and after Page_Load or
before a method call and after a method call. Then, we can use the
application's trace.axd to view which stage consumes most of the times.
If there are any further findings, please feel free to post here also. Good
Luck!
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Troubleshooting IIS "Hang" / Postback Not Working

I have recently added some code to a web application and now I find it
hanging after I do about 2 or 3 postbacks within the application. It hangs
after
doing different things (I cannot find anything in common) and when I run in
Debug mode, it doesn't even appear to be within my code when it hangs (I put
breakpoints all over the place and it doesn't stop at any of them during the
hang).

It hangs after I click a button on the page... but it never reaches the
Page_Load event of the page it is posting back to.. it is like the PostBack
isn't working.

How do I figure out what is going on? What really confuses me is the fact
that the code works the first time but not the second time I run it.. even
with the exact same input data...

It does seem to be related to uploading images... so I went through my code
and made sure I was disposing of all of the image objects in Finally
statements.

Any thoughts on how I can find the problem?

I have ANTS profiler by Red Gate software and I tried doing a memory profile
but it didn't seem to get me anywhere (either that or I wasn't doing it
right).

It is not causing IIS to crash... just to "spin" for a long time. This is
on my development Win XP Pro machine.

After quite some time, I get the following errors when I debug... but I
think they are more a symptom of the non-response to the application as
opposed to the cause of my problem.
-----------
A first chance exception of type 'System.Net.Sockets.SocketException'
occurred in system.dll

Additional information: An existing connection was forcibly closed by the
remote host

A first chance exception of type 'System.IO.IOException' occurred in
system.dll

Additional information: Unable to read data from the transport connection.

LoriHi Lori ,

Welcome to ASP.NET newsgroup.
From your description, one of your asp.net always run into hanging after
you do some modification recently. I'm not quite sure what's your orginally
code logic and what's your modification on them. However, have you been
able to isolate the problem to a certain or some certain individule pages?

Also, based on your error message, I think you're doing some network
transfering task , using Socket or httpwebrequest? Generally, if your
server's CPU utilization is not high and application hangs, it's likely
that there are some thread deadlock in your app or there are some longrun
task in your page's exectution steps which block the server's workthreads.
Would provide some further description on your code logic?

In addition, I suggest you turn on the ASP.NET's trace and use Trace.Write
or Warn to output some trace info in the different stage of those page's
execution lifecycle. For example, before page_load and after Page_Load or
before a method call and after a method call. Then, we can use the
application's trace.axd to view which stage consumes most of the times.

If there are any further findings, please feel free to post here also. Good
Luck!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)