I want to call a class file to return a boolean value. How do I call the method from my CodeBehindPage. I've tried something like this but it doesn't return the value from my Class file.

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{

{
       bool result = true;
       result = Testing.Test123(User.Text, Password.Text);

//Testing is my Class file name and Test123 is the Method name.

       if ((result == true))
             Response.Redirect("~/Test.aspx");
       else
             lblText.Text = "ERROR!";
}

}
}

Recommended Answers

All 3 Replies

Is Test123 static method??! if not you should initiate instance first from Testing class

Testing _testing = new Testing();
_testing.Test123();
//Test123 should be public

My Test123 is a public static. I added what you've said and it shows

Compiler Error Message: CS0176: Member 'Testing.Test123(string, string)' cannot be accessed with an instance reference; qualify it with a type name instead

Give me your testing class code, that's fuzzy!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.