Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Codebehind Example Calling Table Data?


Message #1 by "Jose Haymaker" <ehaymaker@a...> on Thu, 8 Nov 2001 13:33:38
Does anyone have an example using codebehind (in vb) where records are 

pulled out of a table on the .vb page and used to populate the form on 

the .aspx page? 



All I see are examples where form data from .aspx page is submitted from 

the .vb page to a table. 



Can everything in asp.net be done using codebehind?  Or is it limited? 
Message #2 by "S. Asif Imam" <asifimam@y...> on Fri, 9 Nov 2001 09:43:44 +0500
I dont know what you want to do using code behind .Though you can certainly

push your business logic in corresponding vb or cs file.

I been doing component coding in C# and aspx is just reflecting what is in

cs  file.



This example may help out ..else pleasr rephrase what you want to get

through code behind feature.



/***************************************************************************

*/

Person-GetUser.aspx

/***************************************************************************

*/

<%@ Page language="c#" Codebehind="Person-GetUser.aspx.cs"

AutoEventWireup="false" Inherits="WebApplication1.GetUser" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

 <HEAD>

  <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">

  <meta name="CODE_LANGUAGE" Content="C#">

  <meta name="vs_defaultClientScript" content="JavaScript (ECMAScript)">

  <meta name="vs_targetSchema"

content="http://schemas.microsoft.com/intellisense/ie5">

 </HEAD>

 <body MS_POSITIONING="GridLayout">

  <%if (errMsg.Text !=""){%>

  <font face="Verdana" color="blue" size="2">

   <asp:label id="errMsg" runat="server"></asp:label>

  </font>

  <%}%>

  <%else {%>

  <B><FONT face="Verdana, Arial, Helvetica, sans-serif" color="#46462b"

size="4">User

    Details</FONT></B>

  <form id="UserDetails" method="post" runat="server">

   <TABLE height="101" cellSpacing="0" cellPadding="0" width="590"

border="0">

    <TR>

     <TD align="right" width="93">

      <FONT face="Verdana, Arial, Helvetica, sans-serif" size="2"><B>User

Name:&nbsp;&nbsp;</B></FONT>

     </TD>

     <TD width="148">

      <FONT face="Verdana, Arial, Helvetica, sans-serif" color="#0000ff"

size="2"><B>

        <%=UserName %>

       </B></FONT>

     </TD>

     <TD align="right" width="93">

      <FONT face="Verdana, Arial, Helvetica, sans-serif"

size="2"><B>Password:&nbsp;&nbsp;</B></FONT>

     </TD>

     <TD width="148">

      <FONT face="Verdana, Arial, Helvetica, sans-serif" color="#0000ff"

size="2"><B>

        <%=Password%>

       </B></FONT>

     </TD>

    </TR>

    <TR>

     <TD align="right" width="93">

      <FONT face="Verdana, Arial, Helvetica, sans-serif"

size="2"><B>Security

        Level:&nbsp;&nbsp;</B></FONT>

     </TD>

     <TD width="148">

      <FONT face="Verdana, Arial, Helvetica, sans-serif" color="#0000ff"

size="2"><B>

        <%=Security_Level %>

       </B></FONT>

     </TD>

     <TD align="right" width="93">

      <FONT face="Verdana, Arial, Helvetica, sans-serif"

size="2"><B>Ssn:&nbsp;&nbsp;</B></FONT>

     </TD>

     <TD width="148">

      <FONT face="Verdana, Arial, Helvetica, sans-serif" color="#0000ff"

size="2"><B>

        <%=Ssn%>

       </B></FONT>

     </TD>

    </TR>

   </TABLE>

   <HR>

  </form>

  <%}%>

 </body>

</HTML>



/***************************************************************************

*/

Person-GetUser.aspx.cs (VB code will work in same way... not a big

difference.

/***************************************************************************

*/

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;



namespace WebApplication1

{

 /// <summary>

 /// Summary description for GetUser.

 /// </summary>

 public class GetUser : System.Web.UI.Page

 {

  public string Ssn;

  public string UserName;

  public string Password;

  public string Security_Level;

  protected System.Web.UI.WebControls.Label errMsg;



  public GetUser()

  {

   Page.Init += new System.EventHandler(Page_Init);

  }



  private void Page_Load(object sender, System.EventArgs e)

  {

   // Put user code to initialize the page here

   if (!IsPostBack)

   {

    Ssn = Request.Form["ssn"];

    PopulateArray();

   }



  }



  private void Page_Init(object sender, EventArgs e)

  {

   //

   // CODEGEN: This call is required by the ASP.NET Web Form Designer.

   //

   InitializeComponent();

  }



  #region Web Form Designer generated code

  /// <summary>

  /// Required method for Designer support - do not modify

  /// the contents of this method with the code editor.

  /// </summary>

  private void InitializeComponent()

  {

   this.Load += new System.EventHandler(this.Page_Load);



  }

  #endregion

  private void PopulateArray()

  {

   ArrayList myArray;

   DesignPattern.Person pers = new DesignPattern.Person();

   DesignPattern.PersonInfo persInf = new DesignPattern.PersonInfo();

   DesignPattern.UserInfo userInf;

   persInf.Ssn = Ssn;

   myArray = pers.GetUser(persInf);

   if (myArray.Count != 0)

   {

    System.Collections.IEnumerator myEnumerator = myArray.GetEnumerator();

    if ( myEnumerator.MoveNext() )

    {

     userInf = (DesignPattern.UserInfo)myEnumerator.Current;

     UserName = userInf.UserName;

     Password = userInf.Password;

     Security_Level = userInf.Security_Level.ToString();

     Ssn = userInf.Ssn;

    }

   }

   else

   {

    errMsg.Text = "No record found against given search";

   }



  }

 }

}





/***************************************************************************

*/

Description :

I am using Serviced components so you might not need to understand it fully.

Just see Public variables in CS file ..and method PopulateArray(). This

method queries an out sider component to get data .And then initialize

public data members , they are then used in 'aspx' file.

You can access every thing (public) in you code in your aspx page using same

<% %> directive.



Problem solved ????

Let me know if it persists. .









----- Original Message -----

From: "Jose Haymaker" <ehaymaker@a...>

To: "ASP+" <aspx@p...>

Sent: Thursday, November 08, 2001 1:33 PM

Subject: [aspx] Codebehind Example Calling Table Data?





> Does anyone have an example using codebehind (in vb) where records are

> pulled out of a table on the .vb page and used to populate the form on

> the .aspx page?

>

> All I see are examples where form data from .aspx page is submitted from

> the .vb page to a table.

>

> Can everything in asp.net be done using codebehind?  Or is it limited?

> ---

> VBug Winter Conference 2001

>

> Open Forum:  Dan Appleman will be hosting an open

> forum at The .NET Developer's Conference on

> 29th November 2001.  The session will give

> developers the chance to discuss and question

> Dan on his experience with the .NET environment.

> Dan has been programming Visual Basic since the

> alpha version 1.0.  And with over 10 years

> Visual Basic experience is well qualified to

> help you on your road to being a .NET Guru.

>

> http://www.vbug.co.uk/redirect.asp?url=39&id=17

>

> ---

> You are currently subscribed to

> aspx as: asifimam@y...


> $subst('Email.Unsub')




  Return to Index