search, edit and postback

A

Arun Nair

Hi,
I have an Employerregistration pagethat is used to add new Empoyers
to a table. I also have another form search.aspx used to search the
employers(based on their id) and edit the employer details.

My question what is the best way to accept the search criteria and
pass to the Employerregistration page (assuming only a sigle record is
returned). Currently I store the search criteria in the
SearchForm.aspx.cs class and define a get method for it. I declare a
variable of type searchform in the Employerregistration and access the
search criteria.

Also what exactly is a postback ? I have read several definitions but
I still don't get it.

Is this the best way to code your Page_Load when you want to edit a
single record?

thanks,

Arun

public class SearchForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox searchCriteria;
protected System.Web.UI.WebControls.Button btnSearch;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

public String SearchCriteria
{
get { return searchCriteria.Text; }
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSearch.Click += new
System.EventHandler(this.btnSearch_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private void btnSearch_Click(object sender, System.EventArgs e)
{
// Session["searchCritera"] = searchCriteria.Text;
Server.Transfer("./EmployerForm.aspx");
}
}

My Page_Load of the EmployerForm looks like this:
public class EmployerForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox eeno;
protected System.Web.UI.WebControls.RadioButton Organization;
protected System.Web.UI.WebControls.RadioButton Individual;
protected System.Web.UI.WebControls.TextBox employerName;
protected System.Web.UI.WebControls.TextBox contactPerson;
protected System.Web.UI.WebControls.TextBox houseNo;
protected System.Web.UI.WebControls.TextBox street;
protected System.Web.UI.WebControls.Button btnSave;
public SearchForm sf;
private void Page_Load(object sender, System.EventArgs e)
{

sf = (SearchForm)Context.Handler;
// if(IsPostBack) {
SqlConnection conn;
SqlCommand comm;
DataSet ds = new DataSet();
SqlDataAdapter adapter;
string crit = sf.SearchCriteria;
conn = new SqlConnection("Server=sark011Test;uid=sa;pwd=satest;Initial
Catalog=empexchange");
// conn.Open();

// comm = new SqlCommand("select employer_id from employer",
conn);
// adapter = new SqlDataAdapter(comm);
// adapter.Fill(ds);
// // eeno.Text = (string) ds.Tables[0].Rows[0]["employer_id"];
eeno.Text = crit;
// conn.Close();
// }
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top