views:

859

answers:

2

In PageLoad event of the form, I can not reference server side control within logged in template. What am I missing. So when I am logged in I will show text box control otherwise I will show text like "please login to do soso.."

Please help ..

+3  A: 

you can use the FindControl method on your loginview control to get them...

TextBox t = (TextBox)LoginView2.FindControl("TextBox1");
string s = null;

if (t != null)
{
    // textbox is in the current scope of the LoginView
    s = t.text;
}
else
{
    // the textbox is not in the current scope of the LoginView.
}

However, this will only work for the controls that are currently in the shown view of the LoginView control. You'd have to test that you're showing the logged in view before trying to grab the textbox, or you could also test that the FindControl doesn't return a null reference.

Scott Ivey
This is not working. I tried this... TextBox t = (TextBox)LoginView2.FindControl("TextBox1"); string s = t.Text;and this is the error I get...Object reference not set to an instance of an object.
dotnet-practitioner
yes, doesn't work for me too
Marko
A: 

Thank you so much !!!!!

Igor