How to pass value from one form to another form.

Discussion in 'ASP .Net' started by Jay, Jun 28, 2010.

  1. Jay

    Jay Guest

    I have the following code in BookList.aspx:

    <form id="form1" runat="server">
    <div>

    <asp:GridView ID="GridView1" runat="server"
    AutoGenerateColumns="False"
    DataSourceID="LibSysDataSource" AllowPaging="True">
    <Columns>
    <asp:BoundField DataField="AccessionNo"
    HeaderText="Accession No" />
    <asp:BoundField DataField="Title" HeaderText="Title"
    SortExpression="Title" />
    <asp:BoundField DataField="Author" HeaderText="Author"
    SortExpression="Author1LN" />
    </Columns>
    </asp:GridView>
    <asp:AccessDataSource ID="LibSysDataSource" runat="server"
    DataFile="~/App_Data/Library System BE.mdb"
    SelectCommand="SELECT * FROM [Books by Volume] WHERE ([Title]
    LIKE '%' + @Title + '%')">
    <SelectParameters>
    <asp:ControlParameter ControlID="TextBox1" DefaultValue="%"
    Name="Title" PropertyName="Text"
    Type="String" />
    </SelectParameters>
    </asp:AccessDataSource>
    </div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </form>

    I can filter the gridview using the TextBox1 within this form. But I want to
    pass the value from Search.aspx to BookList.aspx.

    Anyone know how to do this?
     
    Jay, Jun 28, 2010
    #1
    1. Advertising

  2. Jay

    Mr. Arnold Guest

    Jay wrote:
    > I have the following code in BookList.aspx:
    >
    > <form id="form1" runat="server">
    > <div>
    >
    > <asp:GridView ID="GridView1" runat="server"
    > AutoGenerateColumns="False"
    > DataSourceID="LibSysDataSource" AllowPaging="True">
    > <Columns>
    > <asp:BoundField DataField="AccessionNo"
    > HeaderText="Accession No" />
    > <asp:BoundField DataField="Title" HeaderText="Title"
    > SortExpression="Title" />
    > <asp:BoundField DataField="Author" HeaderText="Author"
    > SortExpression="Author1LN" />
    > </Columns>
    > </asp:GridView>
    > <asp:AccessDataSource ID="LibSysDataSource" runat="server"
    > DataFile="~/App_Data/Library System BE.mdb"
    > SelectCommand="SELECT * FROM [Books by Volume] WHERE ([Title]
    > LIKE '%' + @Title + '%')">
    > <SelectParameters>
    > <asp:ControlParameter ControlID="TextBox1"
    > DefaultValue="%" Name="Title" PropertyName="Text"
    > Type="String" />
    > </SelectParameters>
    > </asp:AccessDataSource>
    > </div>
    > <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    > </form>
    >
    > I can filter the gridview using the TextBox1 within this form. But I
    > want to pass the value from Search.aspx to BookList.aspx.




    Do you have some code in the CodeBehind file doing a Response.Redirect
    to BookList.aspx on an event in the Search.aspx?
     
    Mr. Arnold, Jun 28, 2010
    #2
    1. Advertising

  3. Jay

    John Morrill Guest

    Greetings Jay!

    A little know but very useful collection for passing data from one aspx page
    to another is the Item collection in the httpcontext.current.request object.
    You can also access this collect via the Context property on you page.

    The life time of the Item collect is during the request process. So yoou and
    put data into the Item collection on one page, do a Server.Transfer to
    another page and retrieve the data from the item collection.

    In your case I assume that you want to do a Server.Transfer from Search.aspx
    to BookList.aspx and pass the value enter on Textbox1 to BookList.aspx.

    The other collection you can use to do this is Session. However this
    collection life time is for the user session. It assumes you have server side
    session enabled. Use can use session to pass data from one page
    response/request cycle to another, but the data will stay in this collection
    until the session ends or you remove it.

    I hope this helps.
    --
    Cheers!

    John


    "Jay" wrote:

    > I have the following code in BookList.aspx:
    >
    > <form id="form1" runat="server">
    > <div>
    >
    > <asp:GridView ID="GridView1" runat="server"
    > AutoGenerateColumns="False"
    > DataSourceID="LibSysDataSource" AllowPaging="True">
    > <Columns>
    > <asp:BoundField DataField="AccessionNo"
    > HeaderText="Accession No" />
    > <asp:BoundField DataField="Title" HeaderText="Title"
    > SortExpression="Title" />
    > <asp:BoundField DataField="Author" HeaderText="Author"
    > SortExpression="Author1LN" />
    > </Columns>
    > </asp:GridView>
    > <asp:AccessDataSource ID="LibSysDataSource" runat="server"
    > DataFile="~/App_Data/Library System BE.mdb"
    > SelectCommand="SELECT * FROM [Books by Volume] WHERE ([Title]
    > LIKE '%' + @Title + '%')">
    > <SelectParameters>
    > <asp:ControlParameter ControlID="TextBox1" DefaultValue="%"
    > Name="Title" PropertyName="Text"
    > Type="String" />
    > </SelectParameters>
    > </asp:AccessDataSource>
    > </div>
    > <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    > </form>
    >
    > I can filter the gridview using the TextBox1 within this form. But I want to
    > pass the value from Search.aspx to BookList.aspx.
    >
    > Anyone know how to do this?
    >
    > .
    >
     
    John Morrill, Jun 28, 2010
    #3
  4. Jay

    James Irvine Guest

    "Jay" <> wrote in message
    news:eiI%...
    >I have the following code in BookList.aspx:
    >
    > <form id="form1" runat="server">
    > <div>
    >
    > <asp:GridView ID="GridView1" runat="server"
    > AutoGenerateColumns="False"
    > DataSourceID="LibSysDataSource" AllowPaging="True">
    > <Columns>
    > <asp:BoundField DataField="AccessionNo"
    > HeaderText="Accession No" />
    > <asp:BoundField DataField="Title" HeaderText="Title"
    > SortExpression="Title" />
    > <asp:BoundField DataField="Author" HeaderText="Author"
    > SortExpression="Author1LN" />
    > </Columns>
    > </asp:GridView>
    > <asp:AccessDataSource ID="LibSysDataSource" runat="server"
    > DataFile="~/App_Data/Library System BE.mdb"
    > SelectCommand="SELECT * FROM [Books by Volume] WHERE ([Title]
    > LIKE '%' + @Title + '%')">
    > <SelectParameters>
    > <asp:ControlParameter ControlID="TextBox1" DefaultValue="%"
    > Name="Title" PropertyName="Text"
    > Type="String" />
    > </SelectParameters>
    > </asp:AccessDataSource>
    > </div>
    > <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    > </form>
    >
    > I can filter the gridview using the TextBox1 within this form. But I want
    > to pass the value from Search.aspx to BookList.aspx.
    >
    > Anyone know how to do this?



    When you say 'pass the value', I'm assumming you just want to pass the text
    box entry, not the result set of the filtered gridview, right? If so, the
    simplest way would be just pass it as a query string:

    string nextPage = "BookList.aspx?textEntered=" + TextBox1.Text;
    Response.Redirect(nextPage);
     
    James Irvine, Jun 28, 2010
    #4
  5. Jay

    Cubaman Guest

    On Jun 28, 4:49 pm, "James Irvine" <> wrote:
    > "Jay" <> wrote in message
    >
    > news:eiI%...
    >
    >
    >
    > >I have the following code in BookList.aspx:

    >
    > >    <form id="form1" runat="server">
    > >    <div>

    >
    > >        <asp:GridView ID="GridView1" runat="server"
    > > AutoGenerateColumns="False"
    > >            DataSourceID="LibSysDataSource" AllowPaging="True">
    > >            <Columns>
    > >                <asp:BoundField DataField="AccessionNo"
    > > HeaderText="Accession No" />
    > >                <asp:BoundField DataField="Title" HeaderText="Title"
    > > SortExpression="Title" />
    > >                <asp:BoundField DataField="Author" HeaderText="Author"
    > >                    SortExpression="Author1LN" />
    > >            </Columns>
    > >        </asp:GridView>
    > >        <asp:AccessDataSource ID="LibSysDataSource" runat="server"
    > >            DataFile="~/App_Data/Library System BE.mdb"
    > >            SelectCommand="SELECT * FROM [Books by Volume] WHERE ([Title]
    > > LIKE '%' + @Title + '%')">
    > >            <SelectParameters>
    > >                <asp:ControlParameter ControlID="TextBox1" DefaultValue="%"
    > > Name="Title" PropertyName="Text"
    > >                    Type="String" />
    > >            </SelectParameters>
    > >        </asp:AccessDataSource>
    > >    </div>
    > >    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    > >    </form>

    >
    > > I can filter the gridview using the TextBox1 within this form. But I want
    > > to pass the value from  Search.aspx to BookList.aspx.

    >
    > > Anyone know how to do this?

    >
    > When you say 'pass the value', I'm assumming you just want to pass the text
    > box entry, not the result set of the filtered gridview, right?  If so, the
    > simplest way would be just pass it as a query string:
    >
    >         string nextPage = "BookList.aspx?textEntered=" + TextBox1.Text;
    >         Response.Redirect(nextPage);


    I'd sugest to html encode every user input to avoid security leaks..
     
    Cubaman, Jun 29, 2010
    #5
  6. Jay

    Mr. Arnold Guest

    Jay wrote:
    > I have the following code in BookList.aspx:
    >
    > <form id="form1" runat="server">
    > <div>
    >
    > <asp:GridView ID="GridView1" runat="server"
    > AutoGenerateColumns="False"
    > DataSourceID="LibSysDataSource" AllowPaging="True">
    > <Columns>
    > <asp:BoundField DataField="AccessionNo"
    > HeaderText="Accession No" />
    > <asp:BoundField DataField="Title" HeaderText="Title"
    > SortExpression="Title" />
    > <asp:BoundField DataField="Author" HeaderText="Author"
    > SortExpression="Author1LN" />
    > </Columns>
    > </asp:GridView>
    > <asp:AccessDataSource ID="LibSysDataSource" runat="server"
    > DataFile="~/App_Data/Library System BE.mdb"
    > SelectCommand="SELECT * FROM [Books by Volume] WHERE ([Title]
    > LIKE '%' + @Title + '%')">
    > <SelectParameters>
    > <asp:ControlParameter ControlID="TextBox1"
    > DefaultValue="%" Name="Title" PropertyName="Text"
    > Type="String" />
    > </SelectParameters>
    > </asp:AccessDataSource>
    > </div>
    > <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    > </form>
    >
    > I can filter the gridview using the TextBox1 within this form. But I
    > want to pass the value from Search.aspx to BookList.aspx.
    >
    > Anyone know how to do this?


    You can also to this using a javascript function on the client-side
    event without having to go to the server-side code behind file.

    <script type="text/javascript">
    <!--
    window.location = "http://www.google.com/"
    //-->
    </script>

    The other line needed would be to find the ID of the Textbox to get the
    string using a GetElementByID.

    "BookList.aspx?somvalue=" + value
     
    Mr. Arnold, Jun 29, 2010
    #6
    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. tom
    Replies:
    4
    Views:
    9,870
    S. Justin Gengo
    Nov 13, 2003
  2. Rabbit
    Replies:
    17
    Views:
    1,495
    Rabbit
    Jun 11, 2006
  3. Robert Cohen
    Replies:
    3
    Views:
    280
    Andrew Durstewitz
    Jul 15, 2003
  4. GavMc
    Replies:
    4
    Views:
    343
    Evertjan.
    Sep 22, 2005
  5. Ivo Roupa
    Replies:
    0
    Views:
    161
    Ivo Roupa
    May 19, 2010
Loading...

Share This Page