Showing posts with label app. Show all posts
Showing posts with label app. Show all posts

Saturday, March 24, 2012

Please Help - Where is the mistake in my code

Hi all

When I run this app, select the checkbox and press the calculate button i get the following error:

Server Error in '/' Application.

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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] nihe.SimpleRent.calculate(Object source, EventArgs e) +173 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1292

My code is as follows, does anyone know what i have done wrong, any help/advice would be very much appreciated.

<%@dotnet.itags.org. Page Language="VB" Debug="true"Inherits="nihe.SimpleRent" ContentType="text/html" ResponseEncoding="iso-8859-1" %><html><body> <form runat="server"> Bathroom with W/C: <asp:CheckBox id="bath_wc" runat="server"></asp:CheckBox> <p> <asp:button id="calcbutton" onclick="calculate" runat="server" text="calculate"></asp:button> </p> </form></body></html>
' SimpleRent.vb'Imports SystemImports System.WebImports System.Web.UIImports System.Web.UI.WebControlsNamespace nihePublic Class SimpleRent : inherits page protected withevents bath_wcAs system.web.ui.webcontrols.checkbox protected withevents row_bwcAs system.web.ui.webcontrols.TableRowPublic sub calculate(source asObject, e as EventArgs) if bath_wc.checked then bath_wc.text ="+3" Context.Items.Add("bath_wc", bath_wc.text) row_bwc.Visible = bath_wc.checked end ifserver.transfer("SimpleResult.aspx")End SubEnd ClassEnd Namespace
<%@dotnet.itags.org. Page Language="vb" %><script runat="server">Sub Page_Load(Source asObject, E as EventArgs) cell_bwc.text ="Bathroom With WC" value_bwc.text = Context.Items("bath_wc")End Sub</script><html><body><form> <asp:Table runat="server"> <asp:TableRow id="row_bwc"> <asp:TableCell id="cell_bwc"></asp:TableCell> <asp:TableCell id ="value_bwc"></asp:TableCell> </asp:TableRow> </asp:Table></form></body></html>

Where did you get this code from?

<html>
<body>
<form>
<asp:Table runat="server">
<asp:TableRow id="row_bwc">
<asp:TableCell id="cell_bwc"></asp:TableCell>
<asp:TableCell id ="value_bwc"></asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>

I see 2 html parts in the code you posted.

Thanks


Because your Calculate method is encapsulated in a page that does not exist. Therefore, "row_bwc" does not exist.

For some reason, it seems you have attempted to create an inheritable base page that is actually a "real" page?


Sorry should have been more specific.

The code show is actaully three seperate pages

page one, codebehind for page one and results page.

Hope this clarifies things

Sorry

Kevin


The last line of your Calculate method attempts to executerow_bwc.Visible = bath_wc.checked. No instance of row_bc has been created. Therefore,row_bc is a null reference.

Remember, there's no row_bc on page one. It's only on the results page.


Lee thanks for reply

So where do i need to reference row_bwc and how do it do it?

Thanks in advance

Kevin


It seems you mix 2 web pages.You have 2 webpages A and B,you can only access controls of A in codebehind of A.

"So where do i need to reference row_bwc and how do it do it?"

You have 2 choice .

1: Combine page one and result page to a single page.That means add:

 <asp:Table runat="server"> <asp:TableRow id="row_bwc"> <asp:TableCell id="cell_bwc"></asp:TableCell> <asp:TableCell id ="value_bwc"></asp:TableCell> </asp:TableRow> </asp:Table>

to page one and don't forget add code in pageload to page one. Then use YourControl.visible to display or hide controls.

2: pass parameter (like row_bwc.Visible,etc )to SimpleResult.aspx then do the action within SimpleResult.aspx.


Kipster:

Lee thanks for reply

So where do i need to reference row_bwc and how do it do it?

Thanks in advance

Kevin

You need to pass the value to set the visibility of row_bwc to the SimpleResult page. You could do this in one of the many ways that you would normally pass values between pages -- like in a QueryString, or drop the Server.Transfer and do a crosspost instead. Let me know if you need an example.

Please help a newbie...

I cannot for the life of me figure out why I cannot run an ASP.NET app. Everytime I try to view in browser/debug I get the error:

maps to a directory outside this application, which is not supported.

I am using Visual Studio 2003. Could someone please enlighten me on what is going wrong here. I am a newbie so if the solution is simple please forgive my ignorance...thanksI have never heard of this error, and it isn't documented in MSDN. My guess is there is a mis-configuration in IIS. Sorry I can't be more specific.
Can you show sources for the page you are trying to view? Especially parts referring to elsewhere (like trying to reference user control etc)

Maybe you can have a look at the following post:

App_GlobalResources maps to a directory outside this application, which is not supported

Hope this helps,

Regards


thanks for posting that link...that is exactly what the problem was. I had a "\" at the end of the file path for the home directory...

thanks again, you saved me

That is so coolBig Smile [:D]

I am happy you solved your problem.

Regards

Friday, March 16, 2012

Please help newb!

I am trying to format the way an asp app populates on the webpage.

The webpage is here:

http://www.merge-efilmknowledgebase.com

The gif at the top and bottom were added to a header and footer .ascx repectively.

I like the way the body will format itself to the size of the browser window.

Is there anyway of doing this with the header and footer gifs as well?

If not, is there a way to proportion the body so that it is always the same width as the header and the footer gifs...maybe insert blank space of some sort?

Cheers!The body is resizing it's self on your site because you have your content tables width set to 100%, this will make the table take up 100% of the browser unless you have it nested inside another table then it will take up 100% of the containing table. You can set the width property to 100% but I wouldn't suggest stretching your gifs because the will look pixelated and crappy. For the footer you could easily replace the image with a table that has it's bgcolor="#000000" and apply a style to your text like <a style="color:#FFFFFF">some text</a> then you could set the width property of the footer table to 100% but I would'nt try and strech any images. You might be screwed on the header.

example:

<table cellpadding="0" cellspacing="0" bgcolor="#000000" or style="color:#000000"width="100%">
<tr>
<td><a style="color:#FFFFFF" href="http://links.10026.com/?link=somesite">click me</a>
</tr>
</table>
Thanks for your reply and help on this one.

I think I will stick with the current format of the header and footer.

Is there anything I can add at the end of the header and / close at the beginning of the footer so the body will no longer take up 100% and instead will format to the same width as the gifs?

Cheers!
you can put everything inside a table with it's width set to whatever width you want like width="768px" and keep your content tables set to width="100%". Then your content tables will take up 100% of the table rather than the browser so they would all ways be 768px or what ever.
Thanks Jeremy123, you helped me fix this one...I am very grateful!