SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    opening one aspx page in another and passing values

    in asp.net i have a grid on a page"(page1.aspx) which is populated with data from database
    when i clcik on a particular row , i get the id of the row.i want to open another page(page2.aspx) by using the id from page1.aspx on a button click.
    i cant use respons.redirect as the original "(page1.aspx)wuld get closed and page2.aspx wuld be dispalyed
    i have used iframe and i am able to view page2.aspx on a button clcik in page1.aspx

    but how do i pass the value(id) so that i culd get that particular row details

    or is there any other way

  2. #2
    SitePoint Addict evilone's Avatar
    Join Date
    Oct 2004
    Location
    Estonia
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think sessions is the answer.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Location
    England
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or is there any other way
    If your feeling upto it, what about Ajax.

    Pseudo overview

    1. Wrap the grid and other controls on Page1.aspx into a Panel; called for this example Panel1. If you have any input text fields, put them into a validation group; again example ValidationGroup1

    2. Wrap all the controls on Page2.aspx and put them in a new panel, called Panel2, and place after Panel1 on Page1.aspx. Any input controls on Panel2, place in own validation group; example ValidationGroup2.

    3. On normal PageLoad, so not postback or Ajax postback. Show Panel1, but hide Panel2 (Use Css to hide panels, not Panel2.Visible = false)

    4. In your grid control just make sure the edit button you currently have contains the following four attributes;
    Code:
    OnCommand="GridEdit_Click" CausesValidation="false" UseSubmitBehavior="false" CommandArgument='<&#37;# Container.DataItemIndex %>'
    5. In your behind code, create the function GridEdit_Click, and place some code like this inside it
    Code:
    int Row;
    if(int.TryParse((string) ((System.Web.UI.WebControls.Button) sender).CommandArgument, out Row))
    {
        Panel1.Style["display"] = "none";
        Panel2.Style["display"] = "block";
    // Row contains the row index the user pressed
    // So populate Panel2 with values from this row
    }
    *Please note, I used Style["display"] = "none", as an example, using css classes would be much better.

    6. On Panel2, you can add submit and cancel buttons to hide Panel2 and reshow Panel1. The submit button should check all the values in ValidationGroup2.

    Now for the advanced stuff
    The really snazzy thing, is to never hide Panel1, but to absolutely position Panel2 over the top of Panel1, so that when Panel2 is visible, it hovers over Panel1, making it clear to the user what will happen next after they hit submit or cancel on Panel2.... they will return to Panel1 to be able to edit more rows.

    There is no limit to how many panels you can add, and if you want something more advanced looking, can use wizards, tabs or any other control type instead of Panels.

    Advantages: Keeps all the logic for the page, within one aspx page instead of spreading it around many aspxs pages. The Ajax means the user never sees a page refresh and so doesn't look at blank pages. You can place ajax busy icons etc to show the user something is happening.

    Disadvantages: Have to use Ajax. Can be slower depending on page size. Involves using css/style setting which you might be against, eg. You want a 100% only asp solution, no stylesheets.

  4. #4
    SitePoint Member
    Join Date
    May 2008
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this can be acheived using Javascript function. Onclientclick you have to call a js function by passing the id as a parameter. In js function using window.open you can open a new window with the new url(page2.aspx?id=xxx) and pass your id as a querystring.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •