Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. HtmlInputHidden in a datagrid loses it's value after postback [modified]

HtmlInputHidden in a datagrid loses it's value after postback [modified]

Scheduled Pinned Locked Moved ASP.NET
csssysadmindockerquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thomasa
    wrote on last edited by
    #1

    I have a datagrid that contains an HtmlInputHidden, something like: <asp:datagrid id="dgCurrency" runat="server" CssClass="grid" AllowPaging="False" CellPadding="0" GridLines="Vertical" AutoGenerateColumns="False" ShowFooter="false" > <Columns> <asp:TemplateColumn HeaderText="ISO kode" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="150px"> <ItemStyle HorizontalAlign="Left" VerticalAlign="Top"></ItemStyle> <ItemTemplate> <asp:Label id="lblISOCode" runat="server" CssClass="tbStyle1"> <%#DataBinder.Eval(Container.DataItem, "strISOCode").ToString()%> </asp:Label> <input type="hidden" runat="server" id="inCurrencyID" value='<%#DataBinder.Eval(Container.DataItem, "lngCurrencyID").ToString()%>' /> </ItemTemplate> </asp:TemplateColumn> ... Where the inCurrencyID is my HtmlInputHidden. At the first time my page loads, I add a DataView to the dgCurrency datasource. When I push a button the first time, the inCurrencyID has it's value, as in: foreach (DataGridItem dgi in dgCurrency.Items) { inCurrencyID = (HtmlInputHidden)dgi.FindControl("inCurrencyID"); int lngCurrencyID = int.Parse(inCurrencyID.Value); ... After this I don't databind the dgCurrency to a new datasource, I just leave it as it is. Now the next time I push the same button, it has now lost it's value???? The same goes for the label lblISOCode. The strange thing is that I also have an TextBox in the DataGrid, and that control stil have it's Text. Dose anyone know why, or is there another hidden fild that I can use that dosen't lose it's value on a PostBack without a databind()? Thanks Thomas

    modified on Thursday, May 15, 2008 9:47 AM

    T 1 Reply Last reply
    0
    • T thomasa

      I have a datagrid that contains an HtmlInputHidden, something like: <asp:datagrid id="dgCurrency" runat="server" CssClass="grid" AllowPaging="False" CellPadding="0" GridLines="Vertical" AutoGenerateColumns="False" ShowFooter="false" > <Columns> <asp:TemplateColumn HeaderText="ISO kode" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="150px"> <ItemStyle HorizontalAlign="Left" VerticalAlign="Top"></ItemStyle> <ItemTemplate> <asp:Label id="lblISOCode" runat="server" CssClass="tbStyle1"> <%#DataBinder.Eval(Container.DataItem, "strISOCode").ToString()%> </asp:Label> <input type="hidden" runat="server" id="inCurrencyID" value='<%#DataBinder.Eval(Container.DataItem, "lngCurrencyID").ToString()%>' /> </ItemTemplate> </asp:TemplateColumn> ... Where the inCurrencyID is my HtmlInputHidden. At the first time my page loads, I add a DataView to the dgCurrency datasource. When I push a button the first time, the inCurrencyID has it's value, as in: foreach (DataGridItem dgi in dgCurrency.Items) { inCurrencyID = (HtmlInputHidden)dgi.FindControl("inCurrencyID"); int lngCurrencyID = int.Parse(inCurrencyID.Value); ... After this I don't databind the dgCurrency to a new datasource, I just leave it as it is. Now the next time I push the same button, it has now lost it's value???? The same goes for the label lblISOCode. The strange thing is that I also have an TextBox in the DataGrid, and that control stil have it's Text. Dose anyone know why, or is there another hidden fild that I can use that dosen't lose it's value on a PostBack without a databind()? Thanks Thomas

      modified on Thursday, May 15, 2008 9:47 AM

      T Offline
      T Offline
      TheWirelessGuy
      wrote on last edited by
      #2

      Possibly enableviewstate flag needs to be set to true. You are using a standard html input item, rather than a dotnet control. This is ok since you set the runat server attribute. You may also want to set the enableviewstate="true" attribute as well. Not sure if this solves it, but worth a try. An alternative would be to use an 'asp:label' tag and set it's visibility to false. This gives you a fully qualified dotnet control, yet is not displayed to the user.

      Steve

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups