Determining hidden key values with the Repeater control

Discussion in 'ASP .Net' started by =?Utf-8?B?U2FuZHBvaW50R3V5?=, Sep 22, 2007.

  1. In the datagrid I would put key values (that I didnt want to display) in
    columns marked not visible, in the gridview I would put them in datakeys.
    Im need to apply greater control over my html, so Im using the Repeater for
    the first time. Ive added a linkbutton and am looking in its ItemCommand
    event. But so far Im unable to figure out how to hide a key value, and then
    determine it in ItemCommand.
    Any help is greatly appreciated!
    Thanks, Mark
     
    =?Utf-8?B?U2FuZHBvaW50R3V5?=, Sep 22, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?U2FuZHBvaW50R3V5?=

    Teemu Keiski Guest

    You could use hidden form field

    e.g <input type="hidden" id="hdValue" runat="server" />

    or just Label contro, which you set Visisble="false"

    in <ItemTemplate>. Bind the value to it (with databinding expression) or set
    in code with ItemDataBound. Then in ItemCommand you could get the value by
    FindControling the hdValue control on the current Item.

    I've explained some background for this type of scenarios:

    Understanding the naming container hierarchy of ASP.NET databound controls
    http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net



    "SandpointGuy" <> wrote in message
    news:...
    > In the datagrid I would put key values (that I didnt want to display) in
    > columns marked not visible, in the gridview I would put them in datakeys.
    > Im need to apply greater control over my html, so Im using the Repeater
    > for
    > the first time. Ive added a linkbutton and am looking in its ItemCommand
    > event. But so far Im unable to figure out how to hide a key value, and
    > then
    > determine it in ItemCommand.
    > Any help is greatly appreciated!
    > Thanks, Mark
     
    Teemu Keiski, Sep 23, 2007
    #2
    1. Advertising

  3. =?Utf-8?B?U2FuZHBvaW50R3V5?=

    James Irvine Guest

    SandpointGuy wrote:
    > In the datagrid I would put key values (that I didnt want to display) in
    > columns marked not visible, in the gridview I would put them in datakeys.
    > Im need to apply greater control over my html, so Im using the Repeater for
    > the first time. Ive added a linkbutton and am looking in its ItemCommand
    > event. But so far Im unable to figure out how to hide a key value, and then
    > determine it in ItemCommand.
    > Any help is greatly appreciated!
    > Thanks, Mark



    protected void DataList1_ItemCommand(Object sender, DataListCommandEventArgs e) // an image was clicked on
    {
    String key = DataList1.DataKeys[e.Item.ItemIndex].ToString();
    ....

    }
     
    James Irvine, Sep 23, 2007
    #3
  4. Visible=false won't work since it won't be rendered to client in the first
    place.

    You can use any suitable control as long as you set css rule display:none.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Teemu Keiski" <> wrote in message
    news:uY11n3a$...
    > You could use hidden form field
    >
    > e.g <input type="hidden" id="hdValue" runat="server" />
    >
    > or just Label contro, which you set Visisble="false"
    >
    > in <ItemTemplate>. Bind the value to it (with databinding expression) or
    > set in code with ItemDataBound. Then in ItemCommand you could get the
    > value by FindControling the hdValue control on the current Item.
    >
    > I've explained some background for this type of scenarios:
    >
    > Understanding the naming container hierarchy of ASP.NET databound controls
    > http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx
    >
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    >
    > "SandpointGuy" <> wrote in message
    > news:...
    >> In the datagrid I would put key values (that I didnt want to display) in
    >> columns marked not visible, in the gridview I would put them in datakeys.
    >> Im need to apply greater control over my html, so Im using the Repeater
    >> for
    >> the first time. Ive added a linkbutton and am looking in its ItemCommand
    >> event. But so far Im unable to figure out how to hide a key value, and
    >> then
    >> determine it in ItemCommand.
    >> Any help is greatly appreciated!
    >> Thanks, Mark

    >
    >
     
    Eliyahu Goldin, Sep 23, 2007
    #4
  5. =?Utf-8?B?U2FuZHBvaW50R3V5?=

    Teemu Keiski Guest

    If you use Label, then visibility doesn't matter. I pointed to using hidden
    Label.

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "Eliyahu Goldin" <> wrote in
    message news:OyHA0hb$...
    > Visible=false won't work since it won't be rendered to client in the first
    > place.
    >
    > You can use any suitable control as long as you set css rule display:none.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Teemu Keiski" <> wrote in message
    > news:uY11n3a$...
    >> You could use hidden form field
    >>
    >> e.g <input type="hidden" id="hdValue" runat="server" />
    >>
    >> or just Label contro, which you set Visisble="false"
    >>
    >> in <ItemTemplate>. Bind the value to it (with databinding expression) or
    >> set in code with ItemDataBound. Then in ItemCommand you could get the
    >> value by FindControling the hdValue control on the current Item.
    >>
    >> I've explained some background for this type of scenarios:
    >>
    >> Understanding the naming container hierarchy of ASP.NET databound
    >> controls
    >> http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx
    >>
    >>
    >> --
    >> Teemu Keiski
    >> AspInsider, ASP.NET MVP
    >> http://blogs.aspadvice.com/joteke
    >> http://teemukeiski.net
    >>
    >>
    >>
    >> "SandpointGuy" <> wrote in message
    >> news:...
    >>> In the datagrid I would put key values (that I didnt want to display) in
    >>> columns marked not visible, in the gridview I would put them in
    >>> datakeys.
    >>> Im need to apply greater control over my html, so Im using the Repeater
    >>> for
    >>> the first time. Ive added a linkbutton and am looking in its
    >>> ItemCommand
    >>> event. But so far Im unable to figure out how to hide a key value, and
    >>> then
    >>> determine it in ItemCommand.
    >>> Any help is greatly appreciated!
    >>> Thanks, Mark

    >>
    >>

    >
    >
     
    Teemu Keiski, Sep 23, 2007
    #5
  6. =?Utf-8?B?U2FuZHBvaW50R3V5?=

    Teemu Keiski Guest

    E.g I'm understanding that he needs the value in ItemCommand when
    client-side visibility isn't needed for the Label. Point would be just grab
    the value in ItemCommand from the Label.


    "Teemu Keiski" <> wrote in message
    news:uOwl9sb$...
    > If you use Label, then visibility doesn't matter. I pointed to using
    > hidden Label.
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    > "Eliyahu Goldin" <> wrote in
    > message news:OyHA0hb$...
    >> Visible=false won't work since it won't be rendered to client in the
    >> first place.
    >>
    >> You can use any suitable control as long as you set css rule
    >> display:none.
    >>
    >> --
    >> Eliyahu Goldin,
    >> Software Developer
    >> Microsoft MVP [ASP.NET]
    >> http://msmvps.com/blogs/egoldin
    >> http://usableasp.net
    >>
    >>
    >> "Teemu Keiski" <> wrote in message
    >> news:uY11n3a$...
    >>> You could use hidden form field
    >>>
    >>> e.g <input type="hidden" id="hdValue" runat="server" />
    >>>
    >>> or just Label contro, which you set Visisble="false"
    >>>
    >>> in <ItemTemplate>. Bind the value to it (with databinding expression) or
    >>> set in code with ItemDataBound. Then in ItemCommand you could get the
    >>> value by FindControling the hdValue control on the current Item.
    >>>
    >>> I've explained some background for this type of scenarios:
    >>>
    >>> Understanding the naming container hierarchy of ASP.NET databound
    >>> controls
    >>> http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx
    >>>
    >>>
    >>> --
    >>> Teemu Keiski
    >>> AspInsider, ASP.NET MVP
    >>> http://blogs.aspadvice.com/joteke
    >>> http://teemukeiski.net
    >>>
    >>>
    >>>
    >>> "SandpointGuy" <> wrote in message
    >>> news:...
    >>>> In the datagrid I would put key values (that I didnt want to display)
    >>>> in
    >>>> columns marked not visible, in the gridview I would put them in
    >>>> datakeys.
    >>>> Im need to apply greater control over my html, so Im using the Repeater
    >>>> for
    >>>> the first time. Ive added a linkbutton and am looking in its
    >>>> ItemCommand
    >>>> event. But so far Im unable to figure out how to hide a key value, and
    >>>> then
    >>>> determine it in ItemCommand.
    >>>> Any help is greatly appreciated!
    >>>> Thanks, Mark
    >>>
    >>>

    >>
    >>

    >
    >
     
    Teemu Keiski, Sep 23, 2007
    #6
  7. It is not only visibility. The fact that a control is not rendered to the
    client means 2 things:

    1. It is not available on client.
    2. It is not available on server on postbacks since the client doesn't have
    the control to send it back.

    It won't be found in ItemCommand.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Teemu Keiski" <> wrote in message
    news:u1Tn6ub$...
    > E.g I'm understanding that he needs the value in ItemCommand when
    > client-side visibility isn't needed for the Label. Point would be just
    > grab the value in ItemCommand from the Label.
    >
    >
    > "Teemu Keiski" <> wrote in message
    > news:uOwl9sb$...
    >> If you use Label, then visibility doesn't matter. I pointed to using
    >> hidden Label.
    >>
    >> --
    >> Teemu Keiski
    >> AspInsider, ASP.NET MVP
    >> http://blogs.aspadvice.com/joteke
    >> http://teemukeiski.net
    >>
    >>
    >> "Eliyahu Goldin" <> wrote in
    >> message news:OyHA0hb$...
    >>> Visible=false won't work since it won't be rendered to client in the
    >>> first place.
    >>>
    >>> You can use any suitable control as long as you set css rule
    >>> display:none.
    >>>
    >>> --
    >>> Eliyahu Goldin,
    >>> Software Developer
    >>> Microsoft MVP [ASP.NET]
    >>> http://msmvps.com/blogs/egoldin
    >>> http://usableasp.net
    >>>
    >>>
    >>> "Teemu Keiski" <> wrote in message
    >>> news:uY11n3a$...
    >>>> You could use hidden form field
    >>>>
    >>>> e.g <input type="hidden" id="hdValue" runat="server" />
    >>>>
    >>>> or just Label contro, which you set Visisble="false"
    >>>>
    >>>> in <ItemTemplate>. Bind the value to it (with databinding expression)
    >>>> or set in code with ItemDataBound. Then in ItemCommand you could get
    >>>> the value by FindControling the hdValue control on the current Item.
    >>>>
    >>>> I've explained some background for this type of scenarios:
    >>>>
    >>>> Understanding the naming container hierarchy of ASP.NET databound
    >>>> controls
    >>>> http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx
    >>>>
    >>>>
    >>>> --
    >>>> Teemu Keiski
    >>>> AspInsider, ASP.NET MVP
    >>>> http://blogs.aspadvice.com/joteke
    >>>> http://teemukeiski.net
    >>>>
    >>>>
    >>>>
    >>>> "SandpointGuy" <> wrote in
    >>>> message news:...
    >>>>> In the datagrid I would put key values (that I didnt want to display)
    >>>>> in
    >>>>> columns marked not visible, in the gridview I would put them in
    >>>>> datakeys.
    >>>>> Im need to apply greater control over my html, so Im using the
    >>>>> Repeater for
    >>>>> the first time. Ive added a linkbutton and am looking in its
    >>>>> ItemCommand
    >>>>> event. But so far Im unable to figure out how to hide a key value,
    >>>>> and then
    >>>>> determine it in ItemCommand.
    >>>>> Any help is greatly appreciated!
    >>>>> Thanks, Mark
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Eliyahu Goldin, Sep 23, 2007
    #7
  8. =?Utf-8?B?U2FuZHBvaW50R3V5?=

    Teemu Keiski Guest

    I'm wondering what you mean. It's not that hard...

    Where is it said that client visibility is key factor in this case? Second:
    Label uses ViewState, it doesn't use postbacks a) itself nor b) does it need
    it, since it relies totally and entirely on ViewState to keep the state. In
    fact it works fine with hidden form field too. In this case postback data is
    not interesting, so ViewState works it out.

    So don't confuse server-side workings with client-side. Control being hidden
    doesn't mean it is unavailable. For client yes, since it's not rendered but
    if it even doesn't post anything back to the server, it's meaningless is it
    hidden or not, especially on server, where it is 100% living control
    instance. Despite visibility

    So, let me put you a sample, which works fine. And I believe it solves the
    OP's question.

    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs)
    If Not Page.IsPostBack Then
    Dim dt As New DataTable
    dt.Columns.Add("Key1", GetType(String))
    dt.Columns.Add("Key2", GetType(String))

    Dim dr As DataRow

    dr = dt.NewRow()
    dr("Key1") = "Key 1 on row 1"
    dr("Key2") = "Key 2 on row 1"
    dt.Rows.Add(dr)

    dr = dt.NewRow()
    dr("Key1") = "Key 1 on row 2"
    dr("Key2") = "Key 2 on row 2"
    dt.Rows.Add(dr)

    dr = dt.NewRow()
    dr("Key1") = "Key 1 on row 3"
    dr("Key2") = "Key 2 on row 3"
    dt.Rows.Add(dr)

    Repeater1.DataSource = dt
    Repeater1.DataBind()


    End If
    End Sub


    Protected Sub Repeater1_ItemCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.RepeaterCommandEventArgs)
    If e.CommandName = "CheckValues" Then
    Dim lblOnRow As Label = DirectCast(e.Item.FindControl("Label1"),
    Label)
    Dim hiddenFieldOnRow As HtmlInputHidden =
    DirectCast(e.Item.FindControl("hidden1"), HtmlInputHidden)

    Response.Write("label1.Text = " & lblOnRow.Text & ",
    hidden1.Value = " & hiddenFieldOnRow.Value)


    End If
    End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:repeater id="Repeater1" runat="server"
    OnItemCommand="Repeater1_ItemCommand">
    <ItemTemplate>
    Row <%#Container.ItemIndex + 1%>
    <asp:Label id="Label1" runat="server" Visible="false"
    Text='<%#Eval("Key1") %>' />
    <input type="hidden" id="hidden1" runat="server" visible="false"
    value='<%#Eval("Key2") %>' />

    <asp:LinkButton ID="LinkButton1" runat="server"
    CommandName="CheckValues" Text="Click me" />
    <br />
    </ItemTemplate>
    </asp:repeater>
    </div>
    </form>
    </body>
    </html>




    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net





    "Eliyahu Goldin" <> wrote in
    message news:OCTjK4b$...
    > It is not only visibility. The fact that a control is not rendered to the
    > client means 2 things:
    >
    > 1. It is not available on client.
    > 2. It is not available on server on postbacks since the client doesn't
    > have the control to send it back.
    >
    > It won't be found in ItemCommand.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Teemu Keiski" <> wrote in message
    > news:u1Tn6ub$...
    >> E.g I'm understanding that he needs the value in ItemCommand when
    >> client-side visibility isn't needed for the Label. Point would be just
    >> grab the value in ItemCommand from the Label.
    >>
    >>
    >> "Teemu Keiski" <> wrote in message
    >> news:uOwl9sb$...
    >>> If you use Label, then visibility doesn't matter. I pointed to using
    >>> hidden Label.
    >>>
    >>> --
    >>> Teemu Keiski
    >>> AspInsider, ASP.NET MVP
    >>> http://blogs.aspadvice.com/joteke
    >>> http://teemukeiski.net
    >>>
    >>>
    >>> "Eliyahu Goldin" <> wrote in
    >>> message news:OyHA0hb$...
    >>>> Visible=false won't work since it won't be rendered to client in the
    >>>> first place.
    >>>>
    >>>> You can use any suitable control as long as you set css rule
    >>>> display:none.
    >>>>
    >>>> --
    >>>> Eliyahu Goldin,
    >>>> Software Developer
    >>>> Microsoft MVP [ASP.NET]
    >>>> http://msmvps.com/blogs/egoldin
    >>>> http://usableasp.net
    >>>>
    >>>>
    >>>> "Teemu Keiski" <> wrote in message
    >>>> news:uY11n3a$...
    >>>>> You could use hidden form field
    >>>>>
    >>>>> e.g <input type="hidden" id="hdValue" runat="server" />
    >>>>>
    >>>>> or just Label contro, which you set Visisble="false"
    >>>>>
    >>>>> in <ItemTemplate>. Bind the value to it (with databinding expression)
    >>>>> or set in code with ItemDataBound. Then in ItemCommand you could get
    >>>>> the value by FindControling the hdValue control on the current Item.
    >>>>>
    >>>>> I've explained some background for this type of scenarios:
    >>>>>
    >>>>> Understanding the naming container hierarchy of ASP.NET databound
    >>>>> controls
    >>>>> http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx
    >>>>>
    >>>>>
    >>>>> --
    >>>>> Teemu Keiski
    >>>>> AspInsider, ASP.NET MVP
    >>>>> http://blogs.aspadvice.com/joteke
    >>>>> http://teemukeiski.net
    >>>>>
    >>>>>
    >>>>>
    >>>>> "SandpointGuy" <> wrote in
    >>>>> message news:...
    >>>>>> In the datagrid I would put key values (that I didnt want to display)
    >>>>>> in
    >>>>>> columns marked not visible, in the gridview I would put them in
    >>>>>> datakeys.
    >>>>>> Im need to apply greater control over my html, so Im using the
    >>>>>> Repeater for
    >>>>>> the first time. Ive added a linkbutton and am looking in its
    >>>>>> ItemCommand
    >>>>>> event. But so far Im unable to figure out how to hide a key value,
    >>>>>> and then
    >>>>>> determine it in ItemCommand.
    >>>>>> Any help is greatly appreciated!
    >>>>>> Thanks, Mark
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Teemu Keiski, Sep 23, 2007
    #8
  9. I presume you tested your sample and it worked. If so, it is a useful piece
    of knowledge, thank you.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin


    "Teemu Keiski" <> wrote in message
    news:eOI1GUe$...
    > I'm wondering what you mean. It's not that hard...
    >
    > Where is it said that client visibility is key factor in this case?

    Second:
    > Label uses ViewState, it doesn't use postbacks a) itself nor b) does it

    need
    > it, since it relies totally and entirely on ViewState to keep the state.

    In
    > fact it works fine with hidden form field too. In this case postback data

    is
    > not interesting, so ViewState works it out.
    >
    > So don't confuse server-side workings with client-side. Control being

    hidden
    > doesn't mean it is unavailable. For client yes, since it's not rendered

    but
    > if it even doesn't post anything back to the server, it's meaningless is

    it
    > hidden or not, especially on server, where it is 100% living control
    > instance. Despite visibility
    >
    > So, let me put you a sample, which works fine. And I believe it solves

    the
    > OP's question.
    >
    > <%@ Page Language="VB" %>
    > <%@ Import Namespace="System.Data" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <script runat="server">
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs)
    > If Not Page.IsPostBack Then
    > Dim dt As New DataTable
    > dt.Columns.Add("Key1", GetType(String))
    > dt.Columns.Add("Key2", GetType(String))
    >
    > Dim dr As DataRow
    >
    > dr = dt.NewRow()
    > dr("Key1") = "Key 1 on row 1"
    > dr("Key2") = "Key 2 on row 1"
    > dt.Rows.Add(dr)
    >
    > dr = dt.NewRow()
    > dr("Key1") = "Key 1 on row 2"
    > dr("Key2") = "Key 2 on row 2"
    > dt.Rows.Add(dr)
    >
    > dr = dt.NewRow()
    > dr("Key1") = "Key 1 on row 3"
    > dr("Key2") = "Key 2 on row 3"
    > dt.Rows.Add(dr)
    >
    > Repeater1.DataSource = dt
    > Repeater1.DataBind()
    >
    >
    > End If
    > End Sub
    >
    >
    > Protected Sub Repeater1_ItemCommand(ByVal source As Object, ByVal e As
    > System.Web.UI.WebControls.RepeaterCommandEventArgs)
    > If e.CommandName = "CheckValues" Then
    > Dim lblOnRow As Label =

    DirectCast(e.Item.FindControl("Label1"),
    > Label)
    > Dim hiddenFieldOnRow As HtmlInputHidden =
    > DirectCast(e.Item.FindControl("hidden1"), HtmlInputHidden)
    >
    > Response.Write("label1.Text = " & lblOnRow.Text & ",
    > hidden1.Value = " & hiddenFieldOnRow.Value)
    >
    >
    > End If
    > End Sub
    > </script>
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    > <head runat="server">
    > <title>Untitled Page</title>
    > </head>
    > <body>
    > <form id="form1" runat="server">
    > <div>
    > <asp:repeater id="Repeater1" runat="server"
    > OnItemCommand="Repeater1_ItemCommand">
    > <ItemTemplate>
    > Row <%#Container.ItemIndex + 1%>
    > <asp:Label id="Label1" runat="server" Visible="false"
    > Text='<%#Eval("Key1") %>' />
    > <input type="hidden" id="hidden1" runat="server"

    visible="false"
    > value='<%#Eval("Key2") %>' />
    >
    > <asp:LinkButton ID="LinkButton1" runat="server"
    > CommandName="CheckValues" Text="Click me" />
    > <br />
    > </ItemTemplate>
    > </asp:repeater>
    > </div>
    > </form>
    > </body>
    > </html>
    >
    >
    >
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    >
    >
    >
    > "Eliyahu Goldin" <> wrote in
    > message news:OCTjK4b$...
    > > It is not only visibility. The fact that a control is not rendered to

    the
    > > client means 2 things:
    > >
    > > 1. It is not available on client.
    > > 2. It is not available on server on postbacks since the client doesn't
    > > have the control to send it back.
    > >
    > > It won't be found in ItemCommand.
    > >
    > > --
    > > Eliyahu Goldin,
    > > Software Developer
    > > Microsoft MVP [ASP.NET]
    > > http://msmvps.com/blogs/egoldin
    > > http://usableasp.net
    > >
    > >
    > > "Teemu Keiski" <> wrote in message
    > > news:u1Tn6ub$...
    > >> E.g I'm understanding that he needs the value in ItemCommand when
    > >> client-side visibility isn't needed for the Label. Point would be just
    > >> grab the value in ItemCommand from the Label.
    > >>
    > >>
    > >> "Teemu Keiski" <> wrote in message
    > >> news:uOwl9sb$...
    > >>> If you use Label, then visibility doesn't matter. I pointed to using
    > >>> hidden Label.
    > >>>
    > >>> --
    > >>> Teemu Keiski
    > >>> AspInsider, ASP.NET MVP
    > >>> http://blogs.aspadvice.com/joteke
    > >>> http://teemukeiski.net
    > >>>
    > >>>
    > >>> "Eliyahu Goldin" <> wrote in
    > >>> message news:OyHA0hb$...
    > >>>> Visible=false won't work since it won't be rendered to client in the
    > >>>> first place.
    > >>>>
    > >>>> You can use any suitable control as long as you set css rule
    > >>>> display:none.
    > >>>>
    > >>>> --
    > >>>> Eliyahu Goldin,
    > >>>> Software Developer
    > >>>> Microsoft MVP [ASP.NET]
    > >>>> http://msmvps.com/blogs/egoldin
    > >>>> http://usableasp.net
    > >>>>
    > >>>>
    > >>>> "Teemu Keiski" <> wrote in message
    > >>>> news:uY11n3a$...
    > >>>>> You could use hidden form field
    > >>>>>
    > >>>>> e.g <input type="hidden" id="hdValue" runat="server" />
    > >>>>>
    > >>>>> or just Label contro, which you set Visisble="false"
    > >>>>>
    > >>>>> in <ItemTemplate>. Bind the value to it (with databinding

    expression)
    > >>>>> or set in code with ItemDataBound. Then in ItemCommand you could get
    > >>>>> the value by FindControling the hdValue control on the current Item.
    > >>>>>
    > >>>>> I've explained some background for this type of scenarios:
    > >>>>>
    > >>>>> Understanding the naming container hierarchy of ASP.NET databound
    > >>>>> controls
    > >>>>>

    http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx
    > >>>>>
    > >>>>>
    > >>>>> --
    > >>>>> Teemu Keiski
    > >>>>> AspInsider, ASP.NET MVP
    > >>>>> http://blogs.aspadvice.com/joteke
    > >>>>> http://teemukeiski.net
    > >>>>>
    > >>>>>
    > >>>>>
    > >>>>> "SandpointGuy" <> wrote in
    > >>>>> message news:...
    > >>>>>> In the datagrid I would put key values (that I didnt want to

    display)
    > >>>>>> in
    > >>>>>> columns marked not visible, in the gridview I would put them in
    > >>>>>> datakeys.
    > >>>>>> Im need to apply greater control over my html, so Im using the
    > >>>>>> Repeater for
    > >>>>>> the first time. Ive added a linkbutton and am looking in its
    > >>>>>> ItemCommand
    > >>>>>> event. But so far Im unable to figure out how to hide a key value,
    > >>>>>> and then
    > >>>>>> determine it in ItemCommand.
    > >>>>>> Any help is greatly appreciated!
    > >>>>>> Thanks, Mark
    > >>>>>
    > >>>>>
    > >>>>
    > >>>>
    > >>>
    > >>>
    > >>
    > >>

    > >
    > >

    >
    >
     
    Eliyahu Goldin, Sep 23, 2007
    #9
  10. =?Utf-8?B?U2FuZHBvaW50R3V5?=

    Teemu Keiski Guest

    Yes, I tested it. I've used the technique several times, so I was confused
    why wouldn't it work in this case. Definately no pun intended.

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "Eliyahu Goldin" <> wrote in
    message news:ueugCAj$...
    >I presume you tested your sample and it worked. If so, it is a useful piece
    > of knowledge, thank you.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    >
    >
    > "Teemu Keiski" <> wrote in message
    > news:eOI1GUe$...
    >> I'm wondering what you mean. It's not that hard...
    >>
    >> Where is it said that client visibility is key factor in this case?

    > Second:
    >> Label uses ViewState, it doesn't use postbacks a) itself nor b) does it

    > need
    >> it, since it relies totally and entirely on ViewState to keep the state.

    > In
    >> fact it works fine with hidden form field too. In this case postback data

    > is
    >> not interesting, so ViewState works it out.
    >>
    >> So don't confuse server-side workings with client-side. Control being

    > hidden
    >> doesn't mean it is unavailable. For client yes, since it's not rendered

    > but
    >> if it even doesn't post anything back to the server, it's meaningless is

    > it
    >> hidden or not, especially on server, where it is 100% living control
    >> instance. Despite visibility
    >>
    >> So, let me put you a sample, which works fine. And I believe it solves

    > the
    >> OP's question.
    >>
    >> <%@ Page Language="VB" %>
    >> <%@ Import Namespace="System.Data" %>
    >>
    >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >>
    >> <script runat="server">
    >>
    >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >> System.EventArgs)
    >> If Not Page.IsPostBack Then
    >> Dim dt As New DataTable
    >> dt.Columns.Add("Key1", GetType(String))
    >> dt.Columns.Add("Key2", GetType(String))
    >>
    >> Dim dr As DataRow
    >>
    >> dr = dt.NewRow()
    >> dr("Key1") = "Key 1 on row 1"
    >> dr("Key2") = "Key 2 on row 1"
    >> dt.Rows.Add(dr)
    >>
    >> dr = dt.NewRow()
    >> dr("Key1") = "Key 1 on row 2"
    >> dr("Key2") = "Key 2 on row 2"
    >> dt.Rows.Add(dr)
    >>
    >> dr = dt.NewRow()
    >> dr("Key1") = "Key 1 on row 3"
    >> dr("Key2") = "Key 2 on row 3"
    >> dt.Rows.Add(dr)
    >>
    >> Repeater1.DataSource = dt
    >> Repeater1.DataBind()
    >>
    >>
    >> End If
    >> End Sub
    >>
    >>
    >> Protected Sub Repeater1_ItemCommand(ByVal source As Object, ByVal e
    >> As
    >> System.Web.UI.WebControls.RepeaterCommandEventArgs)
    >> If e.CommandName = "CheckValues" Then
    >> Dim lblOnRow As Label =

    > DirectCast(e.Item.FindControl("Label1"),
    >> Label)
    >> Dim hiddenFieldOnRow As HtmlInputHidden =
    >> DirectCast(e.Item.FindControl("hidden1"), HtmlInputHidden)
    >>
    >> Response.Write("label1.Text = " & lblOnRow.Text & ",
    >> hidden1.Value = " & hiddenFieldOnRow.Value)
    >>
    >>
    >> End If
    >> End Sub
    >> </script>
    >>
    >> <html xmlns="http://www.w3.org/1999/xhtml" >
    >> <head runat="server">
    >> <title>Untitled Page</title>
    >> </head>
    >> <body>
    >> <form id="form1" runat="server">
    >> <div>
    >> <asp:repeater id="Repeater1" runat="server"
    >> OnItemCommand="Repeater1_ItemCommand">
    >> <ItemTemplate>
    >> Row <%#Container.ItemIndex + 1%>
    >> <asp:Label id="Label1" runat="server" Visible="false"
    >> Text='<%#Eval("Key1") %>' />
    >> <input type="hidden" id="hidden1" runat="server"

    > visible="false"
    >> value='<%#Eval("Key2") %>' />
    >>
    >> <asp:LinkButton ID="LinkButton1" runat="server"
    >> CommandName="CheckValues" Text="Click me" />
    >> <br />
    >> </ItemTemplate>
    >> </asp:repeater>
    >> </div>
    >> </form>
    >> </body>
    >> </html>
    >>
    >>
    >>
    >>
    >> --
    >> Teemu Keiski
    >> AspInsider, ASP.NET MVP
    >> http://blogs.aspadvice.com/joteke
    >> http://teemukeiski.net
    >>
    >>
    >>
    >>
    >>
    >> "Eliyahu Goldin" <> wrote in
    >> message news:OCTjK4b$...
    >> > It is not only visibility. The fact that a control is not rendered to

    > the
    >> > client means 2 things:
    >> >
    >> > 1. It is not available on client.
    >> > 2. It is not available on server on postbacks since the client doesn't
    >> > have the control to send it back.
    >> >
    >> > It won't be found in ItemCommand.
    >> >
    >> > --
    >> > Eliyahu Goldin,
    >> > Software Developer
    >> > Microsoft MVP [ASP.NET]
    >> > http://msmvps.com/blogs/egoldin
    >> > http://usableasp.net
    >> >
    >> >
    >> > "Teemu Keiski" <> wrote in message
    >> > news:u1Tn6ub$...
    >> >> E.g I'm understanding that he needs the value in ItemCommand when
    >> >> client-side visibility isn't needed for the Label. Point would be just
    >> >> grab the value in ItemCommand from the Label.
    >> >>
    >> >>
    >> >> "Teemu Keiski" <> wrote in message
    >> >> news:uOwl9sb$...
    >> >>> If you use Label, then visibility doesn't matter. I pointed to using
    >> >>> hidden Label.
    >> >>>
    >> >>> --
    >> >>> Teemu Keiski
    >> >>> AspInsider, ASP.NET MVP
    >> >>> http://blogs.aspadvice.com/joteke
    >> >>> http://teemukeiski.net
    >> >>>
    >> >>>
    >> >>> "Eliyahu Goldin" <> wrote in
    >> >>> message news:OyHA0hb$...
    >> >>>> Visible=false won't work since it won't be rendered to client in the
    >> >>>> first place.
    >> >>>>
    >> >>>> You can use any suitable control as long as you set css rule
    >> >>>> display:none.
    >> >>>>
    >> >>>> --
    >> >>>> Eliyahu Goldin,
    >> >>>> Software Developer
    >> >>>> Microsoft MVP [ASP.NET]
    >> >>>> http://msmvps.com/blogs/egoldin
    >> >>>> http://usableasp.net
    >> >>>>
    >> >>>>
    >> >>>> "Teemu Keiski" <> wrote in message
    >> >>>> news:uY11n3a$...
    >> >>>>> You could use hidden form field
    >> >>>>>
    >> >>>>> e.g <input type="hidden" id="hdValue" runat="server" />
    >> >>>>>
    >> >>>>> or just Label contro, which you set Visisble="false"
    >> >>>>>
    >> >>>>> in <ItemTemplate>. Bind the value to it (with databinding

    > expression)
    >> >>>>> or set in code with ItemDataBound. Then in ItemCommand you could
    >> >>>>> get
    >> >>>>> the value by FindControling the hdValue control on the current
    >> >>>>> Item.
    >> >>>>>
    >> >>>>> I've explained some background for this type of scenarios:
    >> >>>>>
    >> >>>>> Understanding the naming container hierarchy of ASP.NET databound
    >> >>>>> controls
    >> >>>>>

    > http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx
    >> >>>>>
    >> >>>>>
    >> >>>>> --
    >> >>>>> Teemu Keiski
    >> >>>>> AspInsider, ASP.NET MVP
    >> >>>>> http://blogs.aspadvice.com/joteke
    >> >>>>> http://teemukeiski.net
    >> >>>>>
    >> >>>>>
    >> >>>>>
    >> >>>>> "SandpointGuy" <> wrote in
    >> >>>>> message news:...
    >> >>>>>> In the datagrid I would put key values (that I didnt want to

    > display)
    >> >>>>>> in
    >> >>>>>> columns marked not visible, in the gridview I would put them in
    >> >>>>>> datakeys.
    >> >>>>>> Im need to apply greater control over my html, so Im using the
    >> >>>>>> Repeater for
    >> >>>>>> the first time. Ive added a linkbutton and am looking in its
    >> >>>>>> ItemCommand
    >> >>>>>> event. But so far Im unable to figure out how to hide a key
    >> >>>>>> value,
    >> >>>>>> and then
    >> >>>>>> determine it in ItemCommand.
    >> >>>>>> Any help is greatly appreciated!
    >> >>>>>> Thanks, Mark
    >> >>>>>
    >> >>>>>
    >> >>>>
    >> >>>>
    >> >>>
    >> >>>
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
     
    Teemu Keiski, Sep 24, 2007
    #10
    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. Darren Smith
    Replies:
    5
    Views:
    5,522
    dsmith
    May 10, 2004
  2. Jukka K. Korpela
    Replies:
    1
    Views:
    1,129
    Jonathan N. Little
    Sep 12, 2006
  3. Rick
    Replies:
    3
    Views:
    8,193
    Alexey Smirnov
    Apr 13, 2010
  4. M P
    Replies:
    1
    Views:
    478
  5. SolarCanine
    Replies:
    2
    Views:
    288
    SolarCanine
    Sep 20, 2005
Loading...

Share This Page