|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Accessing the values of textboxes/labels within a functionsome help. I have a vb class file that i am trying to compile into a dll. The class contains a function that needs to reference the values of a text box and a label. When i try to compile the dll ( with the vbc compiler) I am getting wavy lines under the following sections a ) lblLoginMsg.Text b) email.Text I think i need to declare both of these and I have tried using the following style Dim email As System.Web.UI.WebControls.TextBox But i am still getting the same mistake. Can anyone tell me how to do this. Many thanks martin For reference the function is as follows: Public Shared Function submit (ByVal password As String, ByVal email As String) as integer Dim email As System.Web.UI.WebControls.TextBox Dim password As System.Web.UI.WebControls.TextBox ' create instance of Connection and Command objects Dim connection As SqlConnection = _ New SqlConnection(ConfigurationSettings.AppSettings ("ConnectionString")) Dim command As SqlCommand = _ New SqlCommand("SP_Login", connection) command.CommandType = CommandType.StoredProcedure command.Parameters.Add("@Email", email.Text) ' execute command, checking for a user with the e-mail entered connection.Open() Dim customerReader As SqlDataReader = command.ExecuteReader() If customerReader.Read = False Then ' display error, close connection, and exit method lblLoginMsg.Text = "Password/Email combination not recognized" connection.Close() Return End If ' extract user information and close connection Dim customerID As Integer = customerReader("CustomerID") Dim hashedPassword As String = customerReader("Password") connection.Close() ' check password If Hasher.Hash(password.Text) <> hashedPassword Then ' display error lblLoginMsg.Text = "Password/Email combination not recognized" Else ' set session variable, storing customer ID for later retrieval lblLoginMsg.Text("worldshop_CustomerID") = customerID ' redirect user If Not Context.Request.QueryString("ReturnPage") Is Nothing Then Response.Redirect(Context.Request.QueryString("ReturnPage")) Else Response.Redirect("default.aspx") End If End If End Function In general, controls on a web form or windows form are not accessable in a
called class. Are are ways to reference a control in a "parent" object but it is typically easier, simpler and more readable to simply pass the controls to the object or pass the values to the object. Then put the returned result back in the desired control. Simply declaring the control in the called class will not allow you to resolve it. Hope this helps. "martinharvey via DotNetMonster.com" <u14945@uwe> wrote in message news:576428e5e9b65@uwe...Show quoteHide quote > This is probably a very simple thing i am missing but i would be grateful > for > some help. > > I have a vb class file that i am trying to compile into a dll. The class > contains a function that needs to reference the values of > a text box and a label. When i try to compile the dll ( with the vbc > compiler) I am getting wavy lines under the following sections > > a ) lblLoginMsg.Text > > b) email.Text > > I think i need to declare both of these and I have tried using the > following > style > > Dim email As System.Web.UI.WebControls.TextBox > > But i am still getting the same mistake. Can anyone tell me how to do > this. > > Many thanks martin > > For reference the function is as follows: > > Public Shared Function submit (ByVal password As String, ByVal email As > String) as integer > Dim email As System.Web.UI.WebControls.TextBox > Dim password As System.Web.UI.WebControls.TextBox > ' create instance of Connection and Command objects > Dim connection As SqlConnection = _ > New SqlConnection(ConfigurationSettings.AppSettings > ("ConnectionString")) > Dim command As SqlCommand = _ > New SqlCommand("SP_Login", connection) > command.CommandType = CommandType.StoredProcedure > command.Parameters.Add("@Email", email.Text) > > ' execute command, checking for a user with the e-mail entered > connection.Open() > Dim customerReader As SqlDataReader = command.ExecuteReader() > If customerReader.Read = False Then > ' display error, close connection, and exit method > lblLoginMsg.Text = "Password/Email combination not recognized" > connection.Close() > Return > End If > > ' extract user information and close connection > Dim customerID As Integer = customerReader("CustomerID") > Dim hashedPassword As String = customerReader("Password") > connection.Close() > > ' check password > If Hasher.Hash(password.Text) <> hashedPassword Then > ' display error > lblLoginMsg.Text = "Password/Email combination not recognized" > Else > ' set session variable, storing customer ID for later retrieval > lblLoginMsg.Text("worldshop_CustomerID") = customerID > > ' redirect user > If Not Context.Request.QueryString("ReturnPage") Is Nothing Then > Response.Redirect(Context.Request.QueryString("ReturnPage")) > Else > Response.Redirect("default.aspx") > End If > End If > End Function > > -- > Message posted via http://www.dotnetmonster.com Andrew Robinson wrote:
Show quoteHide quote >In general, controls on a web form or windows form are not accessable in a many thanks for your help Andrew>called class. Are are ways to reference a control in a "parent" object but >it is typically easier, simpler and more readable to simply pass the >controls to the object or pass the values to the object. Then put the >returned result back in the desired control. > >Simply declaring the control in the called class will not allow you to >resolve it. > >Hope this helps. > >> This is probably a very simple thing i am missing but i would be grateful >> for >[quoted text clipped - 66 lines] >> End If >> End Function I am still learning how to do this and you lost me a liitle with your explanation For example in the function above i am tring to display a label messgae that dispalys if the email is not found how would i pass the object the object to the control or pass the valu to the object in this case. martin -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net-web-controls/200511/1
Problems with Re-Usable ASP.NET User Control Libraries
FtpWebRequest UploadFile WebCLient Web Server Control and property tree in design time like Font has. Webcontrol custom designer cannot access container data in templated control AutoEventWireUp Problem Newbie Listbox conditional RequiredFieldValidator Hiding a TreeView's root node |
|||||||||||||||||||||||