ASP.NET - how to write a method?

Asked By prasad vjp
08-Sep-11 02:30 AM

protected void Button1_Click(object sender, EventArgs e)

{

if (TextBox1.Text == "")

{

Label1.Text = datetime.now.date.tostring();

}

else

{

Label1.Text = "" + TextBox1.Text;

}

}
which way to write a method in the above coding in a class
help me..

  James H replied to prasad vjp
08-Sep-11 02:38 AM
Hi you need to call the method like this from  the Businees Layer

protected void Button1_Click(object sender, EventArgs e)
  {
    Test objTest = new Test();
    objTest.GetText(TextBox1.Text);
  }
 
In the Class File Test.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
/// <summary>
/// Summary description for Test
/// </summary>
public class Test
{
  public Test()
  {
    //
    // TODO: Add constructor logic here
    //
  }
 
  public string GetText(string tbText)
  {
    String OutputText = String.Empty;
    if (String.IsNullOrEmpty(tbText))
    {
      OutputText = DateTime.Now.Date.ToString();
    }
    else
    {
      OutputText = "" + tbText;
    }
    return OutputText;
  }
}


  James H replied to prasad vjp
08-Sep-11 02:39 AM
Hi a small modification in the code


protected void Button1_Click(object sender, EventArgs e)
  {
  Test objTest = new Test();
   String OutputText=objTest.GetText(TextBox1.Text);
  }
 
In the Class File Test.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
/// <summary>
/// Summary description for Test
/// </summary>
public class Test
{
  public Test()
  {
  //
  // TODO: Add constructor logic here
  //
  }
 
  public string GetText(string tbText)
  {
  String OutputText = String.Empty;
  if (String.IsNullOrEmpty(tbText))
  {
    OutputText = DateTime.Now.Date.ToString();
  }
  else
  {
    OutputText = "" + tbText;
  }
  return OutputText;
  }
}

  dipa ahuja replied to prasad vjp
08-Sep-11 02:49 AM
int getYear(DateTime dt)
{
  return dt.Year;
}
 
int getYear()
{
  return DateTime.Now.Year;
}
 
protected void Button1_Click(object sender, EventArgs e)
{
  if (TextBox1.Text == "")
  {
    int year = getYear(); //return current year
 
  }
  else
  {
    DateTime dt = DateTime.Parse(TextBox1.Text);
    int year2 = getYear(dt);
  }
}
  Reena Jain replied to prasad vjp
08-Sep-11 04:13 AM
hi,

To create an object from a class, you have to set up a variable of that class type. This involves nothing more than typing its name. You create Objects with the new keyword. Like this:

variable_name = new class_name( );

So type the "Emp" of Employee (the name we gave our class). You should see the IntelliSense list appear with you Class on it. So the name of your variable goes on the left of an equals sign. To the right of the equals sign, you need the new keyword. Type a space and the name of your Class again. This time, you need a pair of round brackets after the class name. End the line with a semicolon, as normal.

myclass cls= new myclass ( );

hope  this will help you
Create New Account
help
Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B How can we know a state of a thread? (A) What is use of Interlocked class ? (A) What is a monitor object? (A) What are wait handles? (A) What is ManualResetEvent and Webservices (B)What is an application domain? (B) What is .NET Remoting? (B) Which class does the remote object has to inherit? (I) what are two different types of remote A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object? (A) How will implement Page Fragment Caching? (B) Can you compare ASP.NET
for the users those are in development or want to be a .net developer • To test a Web Service you must create a windows application or web application to consume this cannot be used with indexers, destructors, or types. In C#, the static keyword indicates a class variable. In VB, the equivalent keyword is Shared. Its scoped to the class in which it occurs. Example a. Static int var / / in c#.net b. static void in Sql server as var_name int How do you separate business logic while creating an ASP.NET application? There are two level of asp.net debugging 1. Page level debugging For this we have to edit the page level debugging The control itself will take care of the date display How can you deploy an asp.net application ? You can deploy an ASP.NET Web application using any one of the
a Factory Method (CreateProductFactory()) Click to enlarge BaseProductFactory namespace CodeMentor.Patterns.GOF.Creational.AbstractFactory.Structure { public abstract class BaseProductFactory { protected BaseProductFactory() { } public abstract BaseProductA ProductA { get ; } public abstract BaseProductB ProductB { get ; } } } namespace CodeMentor.Patterns.GOF.Creational.AbstractFactory.Structure { public class ProductFactory1 : BaseProductFactory { public ProductFactory1() { } public override BaseProductA ProductA { get { return new ProductA1 (); } } public override BaseProductB ProductB { get { return new ProductB1
Migration from ASP to ASP.net How to convert ASP site to ASP.NET site using C# http: / / www.asp.net / downloads / archived-v11 / migration-assistants / asp-to-aspnet hi, ASP.NET framework is very much different from unstrucured ASP and there is no correct way to
Doing initial required tests Testing server: Default-First-Site-Name \ SLGC-LRI-SVR-01 Starting test: Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . SLGC-LRI-SVR-01 passed test Connectivity Doing primary tests Testing server: Default-First-Site-Name \ SLGC-LRI-SVR-01 Starting test: Advertising . . . . . . . . . . . . . . . . . . . . . . . . . SLGC-LRI-SVR-01 passed test Advertising Starting test: FrsEvent There are warning or error events within the last 24 hours after the SYSVOL shared. Failing SYSVOL replication problems may cause Group Policy problems. . . . . . . . . . . . . . . . . . . . . . . . . . SLGC-LRI-SVR-01 passed test FrsEvent Starting test: DFSREvent . . . . . . . . . . . . . . . . . . . . . . . . . SLGC-LRI-SVR-01 passed test DFSREvent Starting test: SysVolCheck . . . . . . . . . . . . . . . . . . . . . . . . . SLGC-LRI-SVR-01 passed test SysVolCheck Starting test: KccEvent A