Showing posts with label webform. Show all posts
Showing posts with label webform. Show all posts

Saturday, March 31, 2012

Strange "Object reference not set to an instance of an object" error in webform

I suddenly received an unexpected error in my project. I have been working
on this project for some time without this issue. Nothing has changed in the
form that caused the exception. A little experimentation shows that I cannot
run ANY .NET web project without getting this error:

-----------------------
--

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 1: <%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false"
Codebehind="Login.aspx.vb" Inherits="DataBayWeb.Login" %>
Line 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Line 3: <HTML
Source File: c:\inetpub\wwwroot\DataBayWeb\login.aspx Line: 1

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
System.Web.UI.Control.get_Controls()
System.Web.UI.Control.AddParsedSubObject(Object obj)

System.Web.UI.Control.System.Web.UI.IParserAccesso r.AddParsedSubObject(Objec
t obj)
ASP.Login_aspx.__BuildControlTree(Control __ctrl) in
c:\inetpub\wwwroot\DataBayWeb\login.aspx:1
ASP.Login_aspx.FrameworkInitialize()
System.Web.UI.Page.ProcessRequest()
System.Web.UI.Page.ProcessRequest(HttpContext context)

System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication+IExecutionSte
p.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

Other developers on my team can run the latest version of the project
without an issue. What has happened?

ChrisVery strange indeed. It might sound obscure, but try removing the
space in <%@. Page...

Otherwise, I would be tempted to do the inevitable and reinstall the
framework.

Simon.

Strange Behavior

When I drag and drop my custom control on to the webform, it displays as a little (resizable) square in design.
If I click the html tab to go to html view, then click the Design tab again, the control shows just fine (like a regular textbox).

Is there some event I am missing or a property that needs to be set?

The top is what is looks like when I place the control on the form.
The bottom is what it looks like when I go to html view and then back to design view...

http://vbforums.com/attachment.php?s=&postid=1669737

Any Ideas what is going on?Solution: I had to override the render event.
Like this

Protected Overrides Sub render(output As HtmlTextWriter)
EnsureChildControls()
MyBase.Render()
End Sub

Strange behavior with HttpCookieCollection

Hi,

I created a simple webform, put a test button on it and implemented a
click handler that looks like so:

private void btnTest_Click(object sender, System.EventArgs e)
{
HttpCookieCollection oCookReq =
HttpContext.Current.Request.Cookies;
HttpCookieCollection oCookResp =
HttpContext.Current.Response.Cookies;

int n1 = oCookReq.Count;
int n2 = oCookResp.Count;
bool bIsNull = (oCookResp["someCookieName"] == null);
int n3 = oCookReq.Count;
int n4 = oCookResp.Count;

Response.Write(string.Format("Before: Request = {0}, Response
= {1}<br>", n1, n2));
Response.Write(string.Format("After: Request = {0}, Response
= {1}<br>", n3, n4));
}

When I click the button the test output on the page is:

Before: Request = 1, Response = 0
After: Request = 2, Response = 1

Can anyone explain why the mere act of looking for a cookie in the
response collection would cause one to get added to both the response
and request collections? I tried the test again using a new
HttpCookieCollection (i.e. not one from the current context) and do
not get this behavior. Clues?

Thanks much...

- Aadlaird@.earthlink.net wrote in
news:3f18afd7.184287250@.news.earthlink.net:

> Hi,
> I created a simple webform, put a test button on it and
> implemented a click handler that looks like so:
> private void btnTest_Click(object sender, System.EventArgs e)
> {
> HttpCookieCollection oCookReq =
> HttpContext.Current.Request.Cookies;
> HttpCookieCollection oCookResp =
> HttpContext.Current.Response.Cookies;
> int n1 = oCookReq.Count;
> int n2 = oCookResp.Count;
> bool bIsNull = (oCookResp["someCookieName"] == null);
> int n3 = oCookReq.Count;
> int n4 = oCookResp.Count;
> Response.Write(string.Format("Before: Request = {0},
> Response
>= {1}<br>", n1, n2));
> Response.Write(string.Format("After: Request = {0},
> Response
>= {1}<br>", n3, n4));
> }
>
> When I click the button the test output on the page is:
> Before: Request = 1, Response = 0
> After: Request = 2, Response = 1
> Can anyone explain why the mere act of looking for a cookie in
> the response collection would cause one to get added to both the
> response and request collections? I tried the test again using
> a new HttpCookieCollection (i.e. not one from the current
> context) and do not get this behavior. Clues?

You've stumbled upon a frustrating (and, AFAIK, undocumented) aspect
of the ASP.NET cookies response collection. Simply querying the
collection will create the cookie if it doesn't exist.

Here's an article that explains this in more depth:

http://www.codeproject.com/aspnet/AspNetCookies.asp

Hope this helps.

Chris.
----
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Monday, March 26, 2012

strange error

My webform is working properly for an hour or so.. then suddenly it stops working. No matter what I put inside Page_Load(), Response.Redirect("hhsjdh.aspx"); for example, it doesn´t redirect or seem to care what I type.

I don´t get any errors or so, but empty tables since the mysql data is not fetched.

I have cleaned the cache and tried three different browsers. I rebuild the solution everytime I make a change in a code behind file.

I use sessions and mysql odbc driver 3.51 if that helps.Does the web server you posting to have a proxy server? Even some hardware firewalls come with proxy servers now. If so, it may have chached your page and you will need to clear the server's cache.
restart your IIS may help. type this in command line widow: iisreset /restart. It is possible that your IIS does not work properly.

Thursday, March 22, 2012

Strange HTML button postback

I have a webform with lots of <asp:...controls but I need couple of buttons
that doesn't cause an automatic postback. I use javascript to handle these
buttons. I tried two approaches with different results:

<IMG onmouseup="src='Bitmaps/Controls/measure_over.bmp';"
onmousedown="src='Bitmaps/Controls/measure_pressed.bmp';"
id="measure" onmouseover="src='Bitmaps/Controls/measure_over.bmp';"
style="LEFT: 170px; WIDTH: 24px; POSITION: absolute; TOP: 2px; HEIGHT: 25px"
onclick="buttonClicked(this.id);"
onmouseout="src='Bitmaps/Controls/measure_btn.bmp';"
alt="" src="http://pics.10026.com/?src=Bitmaps/Controls/measure_btn.bmp"
This is working the way I want to, but I can't disable it as I can with a
button. I then replace the IMG with:

INPUT Type="image"

and it makes a postback every time I click on it. Why? A HTML control
should't do that, right? The script itself (buttonClicked) just fills a
hidden field.

/MiroFrom the MSDN Library about the <input typ="image" tag:

------------------------
INPUT type=image Element | input type=image Object
Creates an image control that, when clicked, causes the form to be
immediately submitted.
------------------------

Maybe add "onclick='return false;'" to the tag.

-Jason Kendall
JasonKendall@.hotmail.com

On Tue, 1 Feb 2005 05:55:13 -0800, "Miro"
<Miro@.discussions.microsoft.com> wrote:

>I have a webform with lots of <asp:...controls but I need couple of buttons
>that doesn't cause an automatic postback. I use javascript to handle these
>buttons. I tried two approaches with different results:
><IMG onmouseup="src='Bitmaps/Controls/measure_over.bmp';"
>onmousedown="src='Bitmaps/Controls/measure_pressed.bmp';"
>id="measure" onmouseover="src='Bitmaps/Controls/measure_over.bmp';"
>style="LEFT: 170px; WIDTH: 24px; POSITION: absolute; TOP: 2px; HEIGHT: 25px"
>onclick="buttonClicked(this.id);"
>onmouseout="src='Bitmaps/Controls/measure_btn.bmp';"
>alt="" src="http://pics.10026.com/?src=Bitmaps/Controls/measure_btn.bmp">
>This is working the way I want to, but I can't disable it as I can with a
>button. I then replace the IMG with:
>INPUT Type="image"
>and it makes a postback every time I click on it. Why? A HTML control
>should't do that, right? The script itself (buttonClicked) just fills a
>hidden field.
>/Miro

Strange HTML button postback

I have a webform with lots of <asp:...controls but I need couple of buttons
that doesn't cause an automatic postback. I use javascript to handle these
buttons. I tried two approaches with different results:
<IMG onmouseup="src='Bitmaps/Controls/measure_over.bmp';"
onmousedown="src='Bitmaps/Controls/measure_pressed.bmp';"
id="measure" onmouseover="src='Bitmaps/Controls/measure_over.bmp';"
style="LEFT: 170px; WIDTH: 24px; POSITION: absolute; TOP: 2px; HEIGHT: 25px"
onclick="buttonClicked(this.id);"
onmouseout="src='Bitmaps/Controls/measure_btn.bmp';"
alt="" src="http://pics.10026.com/?src=Bitmaps/Controls/measure_btn.bmp">
This is working the way I want to, but I can't disable it as I can with a
button. I then replace the IMG with:
INPUT Type="image"
and it makes a postback every time I click on it. Why? A HTML control
should't do that, right? The script itself (buttonClicked) just fills a
hidden field.
/MiroFrom the MSDN Library about the <input typ="image" tag:
----
--
INPUT type=image Element | input type=image Object
Creates an image control that, when clicked, causes the form to be
immediately submitted.
----
--
Maybe add "onclick='return false;'" to the tag.
-Jason Kendall
JasonKendall@.hotmail.com
On Tue, 1 Feb 2005 05:55:13 -0800, "Miro"
<Miro@.discussions.microsoft.com> wrote:

>I have a webform with lots of <asp:...controls but I need couple of buttons
>that doesn't cause an automatic postback. I use javascript to handle these
>buttons. I tried two approaches with different results:
><IMG onmouseup="src='Bitmaps/Controls/measure_over.bmp';"
>onmousedown="src='Bitmaps/Controls/measure_pressed.bmp';"
>id="measure" onmouseover="src='Bitmaps/Controls/measure_over.bmp';"
>style="LEFT: 170px; WIDTH: 24px; POSITION: absolute; TOP: 2px; HEIGHT: 25px
"
>onclick="buttonClicked(this.id);"
>onmouseout="src='Bitmaps/Controls/measure_btn.bmp';"
>alt="" src="http://pics.10026.com/?src=Bitmaps/Controls/measure_btn.bmp">
>This is working the way I want to, but I can't disable it as I can with a
>button. I then replace the IMG with:
>INPUT Type="image"
>and it makes a postback every time I click on it. Why? A HTML control
>should't do that, right? The script itself (buttonClicked) just fills a
>hidden field.
>/Miro