code organization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J

    #1

    code organization

    I'm using codebehind in ASP.Net.

    public partial class edit : System.Web.UI.P age
    {
    protected void Page_Load(objec t sender, EventArgs e)
    {
    // populate the dataset, etc.
    txtFirstName.Te xt =
    dsContact.Table s["Contact"].Rows[0]["FName"].ToString();
    txtLastName.Tex t =
    dsContact.Table s["Contact"].Rows[0]["LName"].ToString();
    }

    protected void btnSave_Click(o bject sender, EventArgs e)
    {
    // I would like to do something like this
    dsContact.Table s["Contact"].Rows[0]["FName"] = txtFirstName.Te xt;
    dsContact.Table s["Contact"].Rows[0]["LName"] = txtLastName.Tex t;
    }

    }

    In Page_Load, a few dataset's are populated and the page is updated
    with the results of the datasets. When the Save button is clicked,
    I want to use the same datasets to update the tables in the db.
    What's the best way to make these datasets (like dsContact in the code)
    visible to both Page_Load and btnSave_Click?

    Thanks.


  • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    #2
    RE: code organization

    You should consider storing these DataSets in Session state. In this way they
    will still be available on a postback. Also you should consider surrounding
    your method body in your Page_Load with an if(!IsPostBack) block.
    Finally, you're posting to the wrong group. This belongs in ASP.NET group.
    -- Peter
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    MetaFinder: http://www.blogmetafinder.com


    "J" wrote:
    I'm using codebehind in ASP.Net.
    >
    public partial class edit : System.Web.UI.P age
    {
    protected void Page_Load(objec t sender, EventArgs e)
    {
    // populate the dataset, etc.
    txtFirstName.Te xt =
    dsContact.Table s["Contact"].Rows[0]["FName"].ToString();
    txtLastName.Tex t =
    dsContact.Table s["Contact"].Rows[0]["LName"].ToString();
    }
    >
    protected void btnSave_Click(o bject sender, EventArgs e)
    {
    // I would like to do something like this
    dsContact.Table s["Contact"].Rows[0]["FName"] = txtFirstName.Te xt;
    dsContact.Table s["Contact"].Rows[0]["LName"] = txtLastName.Tex t;
    }
    >
    }
    >
    In Page_Load, a few dataset's are populated and the page is updated
    with the results of the datasets. When the Save button is clicked,
    I want to use the same datasets to update the tables in the db.
    What's the best way to make these datasets (like dsContact in the code)
    visible to both Page_Load and btnSave_Click?
    >
    Thanks.
    >
    >
    >

    Comment

    Working...