Hidden field?

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

    #1

    Hidden field?

    Hi,

    I have WebPage1 which has a link to go to WebPage2. This link passes a value
    to WebPage2. In the page_load event I get this value using
    Request.QuerySt ring and put it in a public data member of WebPage 2.
    WebPage2 has a button on it and when this button is clicked the page is
    posted back to the server.

    My question is when the page is posted back to the server do I still have
    the value that was passed from WebPage1 (Which I had stored in the public
    datamember). If it's not then, I guess I will have to use hidden box and if
    that's the case then, what is the syntax for creating a hidden text box?

    Also, if this WebPage1 creates a datatable in dataset then, can this
    datatable be used in WebPage2. If yes then, how?

    Thanks

    Yatin


  • Lachlan James

    #2
    Hidden field?

    [color=blue]
    >-----Original Message-----
    >Hi,
    >
    >I have WebPage1 which has a link to go to WebPage2. This[/color]
    link passes a value[color=blue]
    >to WebPage2. In the page_load event I get this value using
    >Request.QueryS tring and put it in a public data member of[/color]
    WebPage 2.[color=blue]
    >WebPage2 has a button on it and when this button is[/color]
    clicked the page is[color=blue]
    >posted back to the server.
    >
    >My question is when the page is posted back to the server[/color]
    do I still have[color=blue]
    >the value that was passed from WebPage1 (Which I had[/color]
    stored in the public[color=blue]
    >datamember).[/color]

    No. You only have it when the page first loads. When you
    post back a new instance of your page is created so you
    loose the value in your property.

    If it's not then, I guess I will have to use hidden box
    and if[color=blue]
    >that's the case then, what is the syntax for creating a[/color]
    hidden text box?

    <asp:textbox id="txtHidden" visible="false"
    runat="server" />
    [color=blue]
    >
    >Also, if this WebPage1 creates a datatable in dataset[/color]
    then, can this[color=blue]
    >datatable be used in WebPage2. If yes then, how?[/color]

    This is possible. You could put the datatable in the pages
    Context.Items collection, and do a Server.Transfer to
    WebPage2.

    However you may want to rethink your design, it's not a
    good idea to be passing tables around in the request.
    [color=blue]
    >
    >Thanks
    >
    >Yatin
    >
    >
    >.
    >[/color]

    Comment

    • Natty Gur

      #3
      Re: Hidden field?

      If you need to persist the data between page postback you can also put
      it in the ViewState.

      Natty Gur, CTO
      Dao2Com Ltd.
      34th Elkalay st. Raanana
      Israel , 43000
      Phone Numbers:
      Office: +972-(0)9-7740261
      Fax: +972-(0)9-7740261
      Mobile: +972-(0)58-888377


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Ram

        #4
        Re: Hidden field?

        First question:
        Hidden Field: When your WebPage2 is loading, in the pageload event
        write this line of code to register a hidden variable and set a value
        for it.
        RegisterHiddenF ield("VariableN ame", VariableValue)
        During the post back you can get back the value using
        Request.Form("V ariableName")

        Second question:
        After the code behind page is completed processing all your variables,
        objects created in the page will be no longer available for you to
        use. Because they have only Page level scope. If you want to create an
        object in one page and want to use that in another page, there are
        many ways to do it. You store that object in Session or Application,
        Cache or Static(shared) variable, then you can access them in other
        pages. Application and Cache also will work similar to static
        variables and you will have only one instance of them for all the
        users. If you want to have different objects for different users, you
        need to use a session variable.

        "Yatin Bhuta" <ybuhta@comcast .net> wrote in message news:<DfDXa.665 55$uu5.6110@scc rnsc04>...[color=blue]
        > Hi,
        >
        > I have WebPage1 which has a link to go to WebPage2. This link passes a value
        > to WebPage2. In the page_load event I get this value using
        > Request.QuerySt ring and put it in a public data member of WebPage 2.
        > WebPage2 has a button on it and when this button is clicked the page is
        > posted back to the server.
        >
        > My question is when the page is posted back to the server do I still have
        > the value that was passed from WebPage1 (Which I had stored in the public
        > datamember). If it's not then, I guess I will have to use hidden box and if
        > that's the case then, what is the syntax for creating a hidden text box?
        >
        > Also, if this WebPage1 creates a datatable in dataset then, can this
        > datatable be used in WebPage2. If yes then, how?
        >
        > Thanks
        >
        > Yatin[/color]

        Comment

        Working...