I have created a class to retrieve textbox values and show that on another control.
But when executed I got this error.
Error:'Myclass' does not contain a constructor that takes '0' arguments
Below is my full code .
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyClass._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label" runat="server" Text="ID"></asp:Label> <asp:textbox ID="tbID" runat="server"></asp:textbox><br /> <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label> <asp:textbox ID="tbName" runat="server"></asp:textbox><br /> <asp:Button ID="btnUseClass" runat="server" Text="Use Class" onclick="btnUseClass_Click" /><br /> <asp:Label ID="lblID" runat="server" ></asp:Label> <asp:Label ID="lblName" runat="server" ></asp:Label> </div> </form> </body> </html>
-----------------------------------
Code Behind)Default.aspx.cs
namespace MyClass
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUseClass_Click(object sender, EventArgs e)
{
Test t = new Test();
t.id = tbID.Text;
t.name = tbName.Text;
lblID.Text = t.id;
lblName.Text = t.name;
}
}
}
---------------------------
(class module)Test.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MyClass
{
public class Test
{
public string id;
public string name;
public Test(string id,string name)
{
this.name = name;
this.id = id;
}
}
}
Any help appreciated.
Thanks in advance.
Ben
Mod Edit: Please use code tags when posting your code. Code tags are used like so =>
Thanks,
PsychoCoder

New Topic/Question
Reply




MultiQuote



|