Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing textbox.text as a param

Status
Not open for further replies.

xorl

Programmer
Aug 8, 2006
10
SE
hey

i have a small but annoying problem. im trying to pass one of my textbox controls as a param in a method.


Details:


my textbox is called txtpass.Text


= = = = = = = = = = = = = = = = = = = = = = = = = = =


using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/* this class handles all events done in the main.aspx page */

namespace FrmLogin
{
public partial class Events : System.Web.UI.Page
{

private SqlConn loadserver;

protected void Page_Load(Object Sender, EventArgs es)
{

loadserver = new SqlConn("localhost","root","");
loadserver.Connect();

if (IsPostBack)
{
txtid.Text = "";
}

}

protected void BtnLogin_Click(Object sender, EventArgs e)
{
/* this doesnt work. i want to pass it as a param */
loadserver.CallBack(txtpass.Text);
/* this works however.... */
txtpass.Text = loadserver.CallBack();
}

}
}

= = = = = = = = = = = = = = = = = = = = = = = = = = =

here is my other class...ill just take a small portion of it

= = = = = = = = = = = = = = = = = = = = = = = = = = =

using System;
using System.Data;
using System.Web;
using System.Net.Sockets;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace FrmLogin
{

public class SqlConn
{
private MySqlConnection sqlconn;
private MySqlCommand sqlcmd;
private string connstr;

public SqlConn(string server, string userid, string password)
{
connstr = String.Format("server={0}; userid={1}; password={2}; database=USERS",

server, userid, password);
}

public void Connect()
{
string tmp = "";
if (null != sqlconn)
{
sqlconn.Close();
}
try {
sqlconn = new MySqlConnection(connstr);
sqlconn.Open();
Auth(tmp);
} catch (MySqlException sqlex) {
throw new Exception("Couldn't connect to server: " +sqlex.Message);
} catch (SocketException sex) {
sex = null;
throw new Exception("Check your connection to the database....");
}
}

/* i want to get the value t to the txtpass.Text so that the value shows in my main.aspx page trough the param. */

public string CallBack(string t)
{
t = "server ha server ha";
return t;
}

= = = = = = = = = = = = = = = = = = = = = = = = = = =
 
is this what you are looking for?

protected void BtnLogin_Click(Object sender, EventArgs e)
{
/* this doesnt work. i want to pass it as a param */
loadserver.CallBack(txtpass);
}

public string CallBack(TextBox t)
{
t.Text = "server ha server ha";
}


Known is handfull, Unknown is worldfull
 
no doesnt work because TextBox doesnt exist in the current namespace. Does TextBox exist in another namespace?. In that case i can use the using directive....

Kinda annoying :)
 
Oh....Maybe Webcontrols namespace will do the trick....need to test it....
 
yeah, that will do that

public string CallBack(System.Web.UI.WebControls.TextBox t)
{
t.Text = "server ha server ha";
}


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top