search, edit and postback

Discussion in 'ASP .Net' started by Arun Nair, Aug 13, 2004.

  1. Arun Nair

    Arun Nair Guest

    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();
    // }
    }
    Arun Nair, Aug 13, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. San Diego Guy
    Replies:
    0
    Views:
    544
    San Diego Guy
    Aug 7, 2003
  2. Schultz
    Replies:
    3
    Views:
    555
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  3. =?Utf-8?B?a2Vu?=
    Replies:
    1
    Views:
    10,325
    Wiktor Zychla [C# MVP]
    Jan 23, 2006
  4. Sharon McCarty
    Replies:
    0
    Views:
    248
    Sharon McCarty
    Nov 24, 2004
  5. Abby Lee
    Replies:
    5
    Views:
    396
    Abby Lee
    Aug 2, 2004
Loading...

Share This Page