Lusiphur 185

I just had a thought...

I've never used MarshalByRefObject so I'm not 100% on how it works. I'm assuming that your ILogin interface indirectly initializes your Login class through the statement
[CODE]public class Login : MarshalByRefObject, ILogin[/CODE]is this correct?

Because the only thing I can think of is that the Login class isn't initialized in the .cs file for the webform but I'm sure that it is or you'd be receiving some very angry errors from implementing [CODE]bool st=login.CheckUn(txtun.Text);[/CODE]My assumption here (having not used MarshalByRefObject before) is that the call to[CODE]ILogin login=null;[/CODE] works in a similar way to [CODE]Login myLogin = new Login()[/CODE]Is that correct?

Now, your most recent post about the actual error message gets me thinking that the initialization issue might be in fact the case as the error indicates that you are pointing to a value that isn't initialized somewhere.

Based on the error segment it spat out:

Line 224: private void btnsign_Click(object sender, System.EventArgs e)
Line 225: {
Line 226: bool st=login.CheckUn(txtun.Text);
Line 227: }

It's indicating that one of 2 things (from what I can see) is not 'present' to the system. Those being login.CheckUN or txtun.Text. The issue could be that the .Text value for txtun is being lost somehow in the button click (unlikely since it would at the least provide a "" value) or that (as I theorized above) login is not initialized properly.

Sorry I got so verbose but in the middle of posting a reply to you, you added more ...

Lusiphur 185

Well I'm making the assumption that your DBConnector function is well formed as you didn't include any of it's code but...

Assuming that the db connection properties are well formed I'm not seeing any issues with your code off-hand.

An example of what I generally utilize in web-apps for DB connection would be:
[CODE]
blConn loadConn = new blConn(); //Represents separate class for DB connection strings to mask from primary class

private bool checkUN(string userName)
{
    string connStr = @loadConn.cString;
    SqlConnection loadMsgConn = new SqlConnection(@connStr);
    SqlCommand loadMsgCmd = new SqlCommand();
    loadMsgCmd = loadMsgConn.CreateCommand();
    loadMsgCmd.CommandText = @"select * from Customer_Details where cUser_Name='@un'");
    loadMsgCmd.Parameters.Add("@un", SqlDbType.VarChar);
    loadMsgCmd.Parameters["@un"].Value = userName;
    loadMsgConn.Open();
    int queryReply = loadMsgCmd.ExecuteNonQuery();
    bool respond = false;
    if (queryReply > 0)
    {
        respond = true;
    }
    return respond;
}[/CODE]Bear with my code as the names are from a cut'n'paste from a project I recently was working on.  Essentially, assuming your SQL connection string is correctly set and you pass userName to the process it should return a bool reply based on a 0 or non-0 reply to the SQL query.

Alternately you can do this method:
[CODE]
blConn loadConn = new blConn(); //Represents separate class for DB connection strings to mask from primary class

private bool checkUN(string userName)
{
    bool respond = false;
    string connStr = @loadConn.cString;
    SqlConnection loadMsgConn = new SqlConnection(@connStr);
    SqlDataAdapter loadMsgAdapt = new SqlDataAdapter(@"select * from Customer_Details where cUser_Name='"+userName+"'", loadMsgConn);
    SqlCommandBuilder loadMsgBuilder = new SqlCommandBuilder(loadMsgAdapt);
    DataSet loadMsgSet = new DataSet();
    loadMsgAdapt.Fill(loadMsgSet, "unCheck");
    loadMsgConn.Close();
    if (loadMsgSet.Tables["unCheck"].Rows.Count > 0)
    {
        respond ...

Lusiphur 185

I could be wrong here but textun.Text would be a text box within the web form itself not a variable to be initialized.

The way I'm reading it he's passing the text value of a TextBox named "textun" to a process named "CheckUN" within class "login".

Beyond that, as I look through the code, I'm not seeing any reason (provided all the classes and interfaces are properly initialized) that you wouldn't be receiving a true/false response from your bool inquiry in the above code segments.

As a side note, your sql query to determine merely if there is or isn't a username that matches in the DB can be accomplished using ExecuteNonQuery() instead of using a reader since all you need to know is whether there are rows returned or not. ExecuteNonQuery() will return a numeric value only as an indication of affected rows so your code could be set to trigger on 0 or > 0 results instead. But that's just my thougt on the matter ;)

Lusiphur 185

I was recently having the exact same problem with a listbox control on my site.

The problem, as it turns out, was that the information bindings were being constantly changed every time the page was loaded (postback or otherwise).

I believe that if you change it so that the actual databind process is accomplished within the vb equivalent of below, it might work out for you:
[CODE]
if (Page.IsPostBack == false)
{
...page's databind processes here...
}
[/CODE]
For example on my site's journal view page my Page_Load segment looks like this:
[CODE]
protected void Page_Load(object sender, EventArgs e)
{
//Split query pos 1 = Post Number
string getQuery = ClientQueryString; //obtain variables from passed link ?orig=#&resp=#
string[] querySplit = getQuery.Split('=', '&');
origNum = Convert.ToInt16(querySplit[1].ToString());
listedPage.Text = Convert.ToString(origNum);
if (Page.IsPostBack == false)
{
loadMessageList();
loadRespList(origNum);
}
navButtonSetup();
if (origNum != -1) //if passed replyID != -1 load passed ID
{
loadMessage(origNum);
}
else //if passed replyID == -1 load lowest ID
{
origNum = lowestPost;
loadMessage(lowestPost);
if (Page.IsPostBack == false)
{
loadRespList(lowestPost);
}
navButtonSetup();
}
if (listRespBox.Items.Count > 0)
{
listRespButton.Visible = true;
}
}[/CODE]However if I did the loadRespList or loadMessageList segments outside of the if (Page.IsPostBack == false) constructs I would receive the same error you reported with your code.

I hope this helps! :D Mark as solved if it does.