Users can enter the name and other information in the webpart and the
form launches, and is submtted to the library but I would like the user
to use the same webpart but launch other forms. Is there a way this is
possible without making the first process
redundant in different pages.
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace FindYourStudent.FindYourStudent
{
[ToolboxItemAttribute(false)]
public class FindYourStudent : WebPart
{
TextBox txtFirstName = new TextBox();
TextBox txtLastName = new TextBox();
TextBox txtMiddleName = new TextBox();
TextBox txtZip = new TextBox();
TextBox txtWebID = new TextBox();
TextBox txtWebPassword = new TextBox();
Button btnLocate = new Button();
Label results = new Label();
protected override void CreateChildControls()
{
//Build the controls in a table
Table table = new Table();
table.Rows.Add(Common.RowFromTextBox("Student First Name:", txtFirstName));
table.Rows.Add(Common.RowFromTextBox("Student Middle Name:", txtMiddleName));
table.Rows.Add(Common.RowFromTextBox("Student Last Name:", txtLastName));
table.Rows.Add(Common.RowFromTextBox("Student Zip:", txtZip));
table.Rows.Add(Common.RowFromTextBox("Web ID:", txtWebID));
table.Rows.Add(Common.RowFromTextBox("Web Password:", txtWebPassword));
table.Rows.Add(Common.RowWithAnyButton("Click to locate student", "Find Student", btnLocate));
table.Rows.Add(Common.RowWithLableSpan(results, 2, HorizontalAlign.Center));
//Create the event handler
btnLocate.Click += new EventHandler(btnLocate_Click);
this.Controls.Add(table);
}
private void btnLocate_Click(object sender, EventArgs e)
{
//Validate The feilds are filled
if (txtFirstName.Text.Length==0 )
{
results.Text = "Please enter First Name";
return;
}
if ( txtLastName.Text.Length == 0 )
{
results.Text = "Please enter Last Name";
return;
}
if ( txtZip.Text.Length == 0)
{
results.Text = "Please enter Zip-Code";
return;
}
//Get reference to the list "EnrolledStudents" created from Power School Oracle query
SPWeb web= SPContext.Current.Web;
SPList list = web.Lists.TryGetList("EnrolledStudents");
//Build a CAML query
SPQuery query = new SPQuery();
string q = "<Where><Eq>";
q += "<FieldRef Name='First_Name' /><Value Type='Text'>";
q += txtFirstName.Text + "</Value></Eq>";
q += "<And><Eq><FieldRef Name='Last_Name' /><Value Type='Text'>";
q += txtLastName.Text + " </Value></Eq></And>";
q += "<And><Eq><FieldRef Name='Middle_Name' /><Value Type='Text'>";
q += txtMiddleName.Text + "</Value></Eq></And>";
q += "<And><Eq><FieldRef Name='Zip' /><Value Type='Text'>";
q += txtZip.Text + "</Value></Eq></And>";
q += "<And><Eq><FieldRef Name='Web_ID' /><Value Type='Text'>";
q += txtWebID.Text + "</Value></Eq></And>";
q += "<And><Eq><FieldRef Name='Web_Password' /><Value Type='Text'>";
q += txtWebPassword.Text + "</Value></Eq></And>";
q += "</Where>";
query.Query = q;
SPListItemCollection items = list.GetItems(query);
if (items.Count > 0)
{
results.Text = "No one Found! Try at a later date";
foreach (SPListItem item in items)
{
if ( FixNull( item,"First_Name")==txtFirstName.Text && FixNull(item,"Last_Name")==txtLastName.Text
&& FixNull(item, "Middle_Name") == txtMiddleName.Text && FixNull(item, "Zip") == txtZip.Text && FixNull(item, "Web_ID") == txtWebID.Text && FixNull(item, "Web_Password") == txtWebPassword.Text)
{
// System.Diagnostics.Debug.WriteLine(item.Title);
string href = "<A href='/SL/SitePages/ParentsPermissions.aspx?studentID=" + item["Student_Number"].ToString() + "'>";
results.Text = href + "Found in class of " + item["ClassOf"].ToString() + " student " + item.Title + " Number: " + item["Student_Number"].ToString() + "</A>";
break;
}
}
}
else
{
results.Text = "No one Found! Try at a later date";
}
// web.Dispose();
}