Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Re: save


Message #1 by "Shreekar" <joshishreekar@r...> on 13 Feb 2003 07:35:25 -0000
Hi

You are declaring Inv in Page_Load as
  	Dim Inv as New Inventory(inv_id)
so the variable Inv has a local scope
and hence it is not known to the Save procedure
Also, I think there is some problem in the way you are
calling the events
onclick=btnSave()
In btnSave
call Save(inv) --> here there is no value to inv
also, the Save procedure has two arguments, u r passing only one
u can try something like this
onclick=Save()
In Save, add the line
  	Dim Inv as New Inventory(inv_id)
I dont know how u will pass the id till here, but that can be 
worked out
hope this helps

Regards
Shreekar Joshi

>Subject: method .save call from <asp:button onclick event.. out 
>of scope?
> From: "John Anderson" <john@a...>
>Date: Wed, 12 Feb 2003 07:37:18
>X-Message-Number: 1
>
>Hello I am new to Oop and have read my Asp.net book and then been 
>trying
>to figure out how to do this call..
>I created a class, it is an object that loads a "inventory" wich 
>is a
>category in a website. well it can load an existing, or create a 
>new one.
>it has a .save method.. I am wanting to set some properties and 
>call
>that .save method triggered from an onclick event. I get an 
>Error,
>I am using Onclick=Save() and Save() has the code to add the data 
>to the
>properties and run the .update method.
>
>here is the error and the Code.
>
>Description: An error occurred during the compilation of a 
>resource
>required to service this request. Please review the following 
>specific
>error details and modify your source code appropriately.
>
>Compiler Error Message: BC30451: Name 'Inv' is not declared.
>
>Source Error:
>
>
>
>Line 25: Sub Save(sender as Object, e as EventArgs) ' fill Object 
>with new
>values and write to database
>Line 26:
>Line 27: 	Inv.Name = frminv_Name.text
>Line 28: 	Inv.Description = frminv_description.text
>Line 29: 	inv.save()
>
>
>Here is the Code:
>this is inv_edit.aspx
>
><%@ Page Language="vb" Debug="true" %>
><!-- #include file="Class.aspx" -->
>
><script language="VB" runat="server">
>dim inv_id
>
>Sub Page_Load(Source as Object, E as EventArgs)
> 	if request("inv_id") <> "" then
> 		inv_id = request("inv_id")
> 	end if
>
> 	Dim Inv as New Inventory(inv_id)
>
> 	if not Page.IsPostBack then
> 		PopulateForm(inv)
> 	end if
>End Sub
>
>Sub PopulateForm(inv as object)
>
> 	frminv_Name.text = Inv.Name
> 	frminv_description.text = Inv.Description
>
>End Sub
>Sub Save(sender as Object, e as EventArgs) ' fill Object with new 
>values
>and write to database
>
> 	Inv.Name = frminv_Name.text
> 	Inv.Description = frminv_description.text
> 	inv.save()
>
>
>End Sub
>Sub btnSave()
>Save(inv)
>End Sub
></Script>
><form Name="form1" runat="server">
><table border=1 cellspacing=0>
><tr><td align='right'>Inventory Name:</td><td><asp:textbox
>id="frminv_Name" size="100" Text="" runat="server" /></td></tr>
><tr><td align='right'>Description:</td><td><asp:textbox
>id="frminv_description" runat="server" rows=5 cols="100"
>textmode="multiline"/></td></tr>
><tr><td><asp:button id="button1" Text="Update" 
>onclick="btnSave()"
>runat="server" /></td></tr>
>
></table>
></form>
>
>
>




Regards
Shreekar Joshi

  Return to Index