Visual Studio .NET - regarding ((TextBox)LoginView1.FindControl("UserName")).Text

Asked By A S
23-Aug-07 01:55 PM
 

Can I do

string A = ((TextBox)LoginView1.FindControl("UserName")).Text

?

This will generate an error if that control hasn't been created yet.  This will generate an error if that control hasn't been created yet.

24-Aug-07 09:04 AM

So, it depends on where you call this line of code.

TextBox textBox = (TextBox)LoginView1.FindControl("UserName");

if (textBox != null)
{
   string A = textBox.Text;
}

something like this could work.  something like this could work.

24-Aug-07 11:25 AM

string A="";

system.web.UI.webcontrol myControl = loginview1.findcontrol("username");

if ( (myControl != null) && (myControl.GetType() == TypeOf(TextBox)) )

         a= mycontrol.text;

 

I am still getting same error  I am still getting same error

24-Aug-07 11:29 AM

I am still getting same error:

 Message: Exception of type 'System.Web.HttpUnhandledException' was
thrown.

Hmm, why are you trapping the error?  Hmm, why are you trapping the error?
24-Aug-07 11:50 AM
it will at least tell you why. you may want to post the code that is in the Page_Init and Page_Load events.
Here is the code  Here is the code
24-Aug-07 12:00 PM

Robbe,

I have nothing in Page_Init and Page_Load function. What do I need to put? I am using SQL Server 2000 in the back end; here is the code (Register.aspx):

protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)

{

string userStr = null;

string passStr = null;

string emailStr = null;

string quesStr = null;

string ansStr = null;

string fnameStr = null;

string lnameStr = null;

string compStr = null;

string addStr = null;

string add2Str = null;

string cityStr = null;

string stateStr = null;

string zipStr = null;

string cntyStr = null;

string phoneStr = null;

TextBox user = (TextBox)LoginView1.FindControl("UserName");

if(user.Text != null)

{

userStr = user.Text;

}

TextBox pass =(TextBox)LoginView1.FindControl("Password");

if (pass.Text != null)

{

passStr = pass.Text;

}

TextBox email = (TextBox)LoginView1.FindControl("Email");

if(email.Text != null)

{

emailStr = email.Text;

}

TextBox ques = (TextBox)LoginView1.FindControl("Question");

if (ques.Text != null)

{

quesStr = ques.Text;

}

TextBox ans = (TextBox)LoginView1.FindControl("Answer");

if (ans.Text != null)

{

ansStr = ans.Text;

}

TextBox fname = (TextBox)LoginView1.FindControl("FName");

if (fname.Text != null)

{

fnameStr = fname.Text;

}

TextBox lname = (TextBox)LoginView1.FindControl("LName");

if (lname.Text != null)

{

lnameStr = lname.Text;

}

TextBox comp = (TextBox)LoginView1.FindControl("Company");

if (comp.Text != null)

{

compStr = comp.Text;

}

TextBox add = (TextBox)LoginView1.FindControl("Address");

if (add.Text != null)

{

addStr = add.Text;

}

TextBox add2 = (TextBox)LoginView1.FindControl("Address2");

if (add2.Text != null)

{

add2Str = add2.Text;

}

TextBox city = (TextBox)LoginView1.FindControl("City");

if (city.Text != null)

{

cityStr = city.Text;

}

TextBox state = (TextBox)LoginView1.FindControl("State");

if (state.Text != null)

{

stateStr = state.Text;

}

TextBox zip = (TextBox)LoginView1.FindControl("Zipcode");

if (zip.Text != null)

{

zipStr = zip.Text;

}

TextBox cnty = (TextBox)LoginView1.FindControl("Country");

if (cnty.Text != null)

{

cntyStr = cnty.Text;

}

TextBox phone = (TextBox)LoginView1.FindControl("Phone");

if (phone.Text != null)

{

phoneStr = phone.Text;

}

long acctno = CatalogAccess.InsertAccount(userStr, passStr, emailStr, quesStr, ansStr, fnameStr, lnameStr, compStr, addStr, add2Str, cityStr, stateStr, zipStr, cntyStr, phoneStr, Request.ServerVariables["REMOTE_ADDR"]);

Roles.AddUserToRole((sender as CreateUserWizard).UserName,

"Customers");

}

 

Let me know if you want to see also aspx code..

Ok. that is why I am having  problems with Register.aspx and Login.aspx  Ok. that is why I am having problems with Register.aspx and Login.aspx
24-Aug-07 12:49 PM
Ok. that is why I am having problems with Register.aspx and Login.aspx. Can you tell what goes into Page_Init and Page_Load? I have not found any thing which is complete information for LoginView. Please help!!
Error occurs when I hit sign up button (there is not problem loading the control)  Error occurs when I hit sign up button (there is not problem loading the control)
24-Aug-07 03:59 PM
Error occurs when I hit sign up button (there is not problem loading the control)
Two things  Two things
24-Aug-07 04:10 PM

 

// You didn't put any error trapping code as I
// asked you to.

try
{
   your code goes here
}
catch (Exception ex)
{
   Debug.WriteLine(ex.Message);
}

// You are still attempting to reference an
// object's property found dynamically without
// confirming that the object was found:

if(user.Text != null)

should be

if (user != null)
{
   string A = user.Text;
}
Here is the error:  Here is the error:
24-Aug-07 05:04 PM

Error occured during loading the page now. Here is the error:

 

Page location: /Register.aspx

Message: D:\hshome\www.company.com\Register.aspx.cs(130): error
CS0122: 'System.Configuration.Debug' is inaccessible due to its
protection level

Source: System.Web

Method: System.CodeDom.Compiler.CompilerResults Compile()

Stack Trace:

   at System.Web.Compilation.AssemblyBuilder.Compile()
   at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
   at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath
virtualPath)
   at
System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean
allowBuildInPrecompile)
   at
System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild,
Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at
System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp,
Boolean noAssert)
   at
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context,
Boolean allowCrossApp, Boolean noAssert)
   at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
   at
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath
virtualPath, String physicalPath)
   at System.Web.HttpApplication.MapHttpHandler(HttpContext context,
String requestType, VirtualPath path, String pathTranslated, Boolean
useAppConfig)
   at
System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)

 

 

 

 

HERE IS my code:

protected void Page_Load(object sender, EventArgs e)

{

 

}

 

protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)

{

try

{

string userStr = null;

string passStr = null;

string emailStr = null;

string quesStr = null;

string ansStr = null;

string fnameStr = null;

string lnameStr = null;

string compStr = null;

string addStr = null;

string add2Str = null;

string cityStr = null;

string stateStr = null;

string zipStr = null;

string cntyStr = null;

string phoneStr = null;

TextBox user = (TextBox)LoginView1.FindControl("UserName");

if(user != null)

{

userStr = user.Text;

}

TextBox pass =(TextBox)LoginView1.FindControl("Password");

if (pass != null)

{

passStr = pass.Text;

}

TextBox email = (TextBox)LoginView1.FindControl("Email");

if(email != null)

{

emailStr = email.Text;

}

TextBox ques = (TextBox)LoginView1.FindControl("Question");

if (ques != null)

{

quesStr = ques.Text;

}

TextBox ans = (TextBox)LoginView1.FindControl("Answer");

if (ans != null)

{

ansStr = ans.Text;

}

TextBox fname = (TextBox)LoginView1.FindControl("FName");

if (fname != null)

{

fnameStr = fname.Text;

}

TextBox lname = (TextBox)LoginView1.FindControl("LName");

if (lname != null)

{

lnameStr = lname.Text;

}

TextBox comp = (TextBox)LoginView1.FindControl("Company");

if (comp != null)

{

compStr = comp.Text;

}

TextBox add = (TextBox)LoginView1.FindControl("Address");

if (add != null)

{

addStr = add.Text;

}

TextBox add2 = (TextBox)LoginView1.FindControl("Address2");

if (add2 != null)

{

add2Str = add2.Text;

}

TextBox city = (TextBox)LoginView1.FindControl("City");

if (city != null)

{

cityStr = city.Text;

}

TextBox state = (TextBox)LoginView1.FindControl("State");

if (state != null)

{

stateStr = state.Text;

}

TextBox zip = (TextBox)LoginView1.FindControl("Zipcode");

if (zip != null)

{

zipStr = zip.Text;

}

TextBox cnty = (TextBox)LoginView1.FindControl("Country");

if (cnty != null)

{

cntyStr = cnty.Text;

}

TextBox phone = (TextBox)LoginView1.FindControl("Phone");

if (phone != null)

{

phoneStr = phone.Text;

}

long acctno = CatalogAccess.InsertAccount(userStr, passStr, emailStr, quesStr, ansStr, fnameStr, lnameStr, compStr, addStr, add2Str, cityStr, stateStr, zipStr, cntyStr, phoneStr, Request.ServerVariables["REMOTE_ADDR"]);

Roles.AddUserToRole((sender as CreateUserWizard).UserName,

"Customers");

}

catch (Exception ex)

{

Debug.WriteLine(ex.Message);

}

}

Even changing protected to public did not help  Even changing protected to public did not help
24-Aug-07 07:52 PM

I even changed protected to public and it did not help also..

Do you have this at the top of your page?  Do you have this at the top of your page?
25-Aug-07 08:15 AM

using System.Diagnostics;

That is the namespace for using the Debug class.

After including System.Diagnostics namespace, I am getting following error  After including System.Diagnostics namespace, I am getting following error
25-Aug-07 03:07 PM

After including System.Diagnostics namespace, I am getting following error:

 

Page location: /Register.aspx

Message: Exception of type 'System.Web.HttpUnhandledException' was
thrown.

Source: System.Web

Method: Boolean HandleError(System.Exception)

Stack Trace:

   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext
context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.register_aspx.ProcessRequest(HttpContext context) in
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary http://asp.net/
Files\root\2a41e1e6\66c5bd74\App_Web_register.aspx.cdcab7d2.rmm3anpn.0.cs:line 0
   at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)

any suggestions?  any suggestions?
29-Aug-07 09:50 AM
end of post
Create New Account
help
visual studio.net 2003 and Access 2007 database .NET Framework Hi I am currently using Visual Studio.Net 2003 running on Windows Server 2000 operating system. I have used Visual Studio.net 2003 connecting to Access 2002 databases in the pass with great success. Now
Visual Studio .net .NET Framework Hi NG, ich habe vor längerer Zeit mit Visual Studio .Net 2003 gearbeitet und überlege momentan auf einen neueren Stand upzudaten. Ein Visual Studio .Net 2008 scheint es nicht zu geben. Habe zumindest mit googeln nichts gefunden. Was
Wise for Visual Studio.NET Wise for Visual Studio.NET By Peter A. Bromberg, Ph.D. To "Print This Page" Link Peter Bromberg Wise for Visual Studio .NET is a total and complete installation development system for creating and editing Windows® Installer
Visual Studio versioning . . . . how to tell? .NET Framework To my knowledge, Visual studio 6 was released in 1998, then Visual Studio .NET 2002 is VS 7, then Visual Studio .NET 2003 is VS 7.1, then Visual
Is Visual Studio self-hosting ? .NET Framework Does Microsoft use Visual Studio IDE, Visual Studio Debugger, Visual Studio Linker and Visual Studio compiler for developing Visual Studio ? Or is Visual Studio not