3 Replies - 3923 Views - Last Post: 23 November 2009 - 08:34 AM Rate Topic: -----

#1 aks29921  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 84
  • View blog
  • Posts: 230
  • Joined: 24-August 09

Calling function on button click

Posted 22 November 2009 - 07:36 AM

Hello frnds of DIC..
I have previously worked on windows applications in VB.NET & C#.NET but am new to ASP.NET

I have made a web page in my application where i have to call a function made in a separate class file on the click of the submit button
Here's what i tried:
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

	Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
		Dim dl As DataLayer
		dl.Product_Insert(pcode.Text, pname.Text, cat.Text, ptype.Text, comp.Text, desc.Text, dept.Text, qavail.Text, qsold.Text, qmin.Text, qpack.Text, Unit.Text, mrp.Text, disc.Text, prc.Text, spoff.Text, tax.Text)
	End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>Add Product</title>
	<style type="text/css">
		#Submit
		{
			height: 40px;
		}
	</style>
</head>
<body>
  <form id="form1" runat="server">
<div align="center">
	<div class="row">
	  <span class="label">Product Code:</span>
	  <span class="txt"><input type="text" id="pcode"/></span>
	</div>
	<div class="row">
	  <span class="label">Product Name:</span>
	  <span class="txt"><input type="text" id="pname"/></span>
	</div>
	<div class="row">
	  <span class="label">Product Category:</span>
	  <span class="txt"><input type="text" id="cat"/></span>
	</div>
	<div class="row">
	  <span class="label">Product Type:</span>
	  <span class="txt"><input type="text" id="ptype"/></span>
	</div>
	<div class="row">
	  <span class="label">Product Company:</span>
	  <span class="txt"><input type="text" id="comp"/></span>
	</div>
	<div class="row">
	  <span class="label">Product Description:</span>
	  <span class="txt"><input type="text" id="desc"/></span>
	</div>
	<div class="row">
	  <span class="label">Product Department:</span>
	  <span class="txt"><input type="text" id="dept"/></span>
	</div>
	<div class="row">
	  <span class="label">Quantity Available:</span>
	  <span class="txt"><input type="text" id="qavail"/></span>
	</div>
	<div class="row">
	  <span class="label">Quantity Sold:</span>
	  <span class="txt"><input type="text" id="qsold"/></span>
	</div> 
		<div class="row">
	  <span class="label">Quantity Minimum Inventory:</span>
	  <span class="txt"><input type="text" id="qmin"/></span>
	</div> 
	<div class="row">
	  <span class="label">Quantity Packing:</span>
	  <span class="txt"><input type="text" id="qpack"/></span>
	</div> 
	<div class="row">
	  <span class="label">Product Unit:</span>
	  <span class="txt"><input type="text" id="unit"/></span>
	</div>  
	<div class="row">
	  <span class="label">Product MRP:</span>
	  <span class="txt"><input type="text" id="mrp"/></span>
	</div>	
	<div class="row">
	  <span class="label">Product Discount:</span>
	  <span class="txt"><input type="text" id="disc"/></span>
	</div>  
	<div class="row">
	  <span class="label">Product Price:</span>
	  <span class="txt"><input type="text" id="prc"/></span>
	</div> 
	<div class="row">
	  <span class="label">Product Special Offer:</span>
	  <span class="txt"><input type="text" id="spoff"/></span>
	</div> 
	<div class="row">
	  <span class="label">Product Tax:</span>
	  <span class="txt"><input type="text" id="tax"/></span>
	</div> 
	  <asp:Button ID="Submit" runat="server" Text="OK" />
</div> 
  
  </form>  
</body>
</html>


but it doesn't work.....

However, there is no problem in the Product_Insert function and the connection to the database is also properly made as i have made similar functions earlier in my windows applications. Since i am confident about that part, i did not deem it necessary to post my code of Product_Insert() here.
Although i would like to add that the Product_Insert() is in DataLayer.vb inside the App_Code folder of my project.

Could anyone suggest where i am going wrong?

I am sure there must be some elementary mistake or my approach must be wrong as this is the first ASP.NET application that i am designing...
In case my approach is wrong here, kindly guide me towards the correct way of doing what i want..
Any help will be greatly appreciated..

This post has been edited by aks29921: 22 November 2009 - 07:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Calling function on button click

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Calling function on button click

Posted 22 November 2009 - 09:41 AM

Are you getting any errors?

What happens when you debug and put a break on the Product_Insert method call?

Are you able to step through the code and see if it is all working correctly?
Was This Post Helpful? 0
  • +
  • -

#3 aks29921  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 84
  • View blog
  • Posts: 230
  • Joined: 24-August 09

Re: Calling function on button click

Posted 22 November 2009 - 09:53 AM

View PostJayman, on 22 Nov, 2009 - 08:41 AM, said:

Are you getting any errors?

What happens when you debug and put a break on the Product_Insert method call?

Are you able to step through the code and see if it is all working correctly?

Quote

dl.Product_Insert(pcode.Text, pname.Text, cat.Text, ptype.Text, comp.Text, desc.Text, dept.Text, qavail.Text, qsold.Text, qmin.Text, qpack.Text, Unit.Text, mrp.Text, disc.Text, prc.Text, spoff.Text, tax.Text)

in the above line of function call the visual studio is giving errors on the textbox ids (i.e. underlining pcode, pname etc in blue)....

so, when i try to debug my application, it gives errors for all these 17 ids like
"Name 'pcode' is not declared" & similarly for others too..

am really stuck!!

plz help me out....

This post has been edited by aks29921: 22 November 2009 - 11:00 AM

Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Calling function on button click

Posted 23 November 2009 - 08:34 AM

Include the runat="server" tag for those controls that you are trying to access from the code-behind.

Example:
<input type="text" id="pcode" runat="server"/>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1