Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Determining hidden key values with the Repeater control

Reply
Thread Tools

Determining hidden key values with the Repeater control

 
 
=?Utf-8?B?U2FuZHBvaW50R3V5?=
Guest
Posts: n/a
 
      09-22-2007
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
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      09-23-2007
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/ar...-controls.aspx


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



"SandpointGuy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
James Irvine
Guest
Posts: n/a
 
      09-23-2007
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();
....

}

 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      09-23-2007
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" <(E-Mail Removed)> wrote in message
news:uY11n3a$(E-Mail Removed)...
> 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/ar...-controls.aspx
>
>
> --
> Teemu Keiski
> AspInsider, ASP.NET MVP
> http://blogs.aspadvice.com/joteke
> http://teemukeiski.net
>
>
>
> "SandpointGuy" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      09-23-2007
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" <(E-Mail Removed)> wrote in
message news:OyHA0hb$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:uY11n3a$(E-Mail Removed)...
>> 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/ar...-controls.aspx
>>
>>
>> --
>> Teemu Keiski
>> AspInsider, ASP.NET MVP
>> http://blogs.aspadvice.com/joteke
>> http://teemukeiski.net
>>
>>
>>
>> "SandpointGuy" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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

>>
>>

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      09-23-2007
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" <(E-Mail Removed)> wrote in message
news:uOwl9sb$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in
> message news:OyHA0hb$(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:uY11n3a$(E-Mail Removed)...
>>> 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/ar...-controls.aspx
>>>
>>>
>>> --
>>> Teemu Keiski
>>> AspInsider, ASP.NET MVP
>>> http://blogs.aspadvice.com/joteke
>>> http://teemukeiski.net
>>>
>>>
>>>
>>> "SandpointGuy" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> 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
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      09-23-2007
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" <(E-Mail Removed)> wrote in message
news:u1Tn6ub$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:uOwl9sb$(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in
>> message news:OyHA0hb$(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:uY11n3a$(E-Mail Removed)...
>>>> 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/ar...-controls.aspx
>>>>
>>>>
>>>> --
>>>> Teemu Keiski
>>>> AspInsider, ASP.NET MVP
>>>> http://blogs.aspadvice.com/joteke
>>>> http://teemukeiski.net
>>>>
>>>>
>>>>
>>>> "SandpointGuy" <(E-Mail Removed)> wrote in
>>>> message news:(E-Mail Removed)...
>>>>> 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
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      09-23-2007
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" <(E-Mail Removed)> wrote in
message news:OCTjK4b$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:u1Tn6ub$(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:uOwl9sb$(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in
>>> message news:OyHA0hb$(E-Mail Removed)...
>>>> 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" <(E-Mail Removed)> wrote in message
>>>> news:uY11n3a$(E-Mail Removed)...
>>>>> 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/ar...-controls.aspx
>>>>>
>>>>>
>>>>> --
>>>>> Teemu Keiski
>>>>> AspInsider, ASP.NET MVP
>>>>> http://blogs.aspadvice.com/joteke
>>>>> http://teemukeiski.net
>>>>>
>>>>>
>>>>>
>>>>> "SandpointGuy" <(E-Mail Removed)> wrote in
>>>>> message news:(E-Mail Removed)...
>>>>>> 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
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      09-23-2007
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" <(E-Mail Removed)> wrote in message
news:eOI1GUe$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in
> message news:OCTjK4b$(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:u1Tn6ub$(E-Mail Removed)...
> >> 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" <(E-Mail Removed)> wrote in message
> >> news:uOwl9sb$(E-Mail Removed)...
> >>> 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" <(E-Mail Removed)> wrote in
> >>> message news:OyHA0hb$(E-Mail Removed)...
> >>>> 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" <(E-Mail Removed)> wrote in message
> >>>> news:uY11n3a$(E-Mail Removed)...
> >>>>> 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/ar...-controls.aspx
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Teemu Keiski
> >>>>> AspInsider, ASP.NET MVP
> >>>>> http://blogs.aspadvice.com/joteke
> >>>>> http://teemukeiski.net
> >>>>>
> >>>>>
> >>>>>
> >>>>> "SandpointGuy" <(E-Mail Removed)> wrote in
> >>>>> message news:(E-Mail Removed)...
> >>>>>> 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
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>
> >>>
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      09-24-2007
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" <(E-Mail Removed)> wrote in
message news:ueugCAj$(E-Mail Removed)...
>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" <(E-Mail Removed)> wrote in message
> news:eOI1GUe$(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in
>> message news:OCTjK4b$(E-Mail Removed)...
>> > 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" <(E-Mail Removed)> wrote in message
>> > news:u1Tn6ub$(E-Mail Removed)...
>> >> 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" <(E-Mail Removed)> wrote in message
>> >> news:uOwl9sb$(E-Mail Removed)...
>> >>> 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" <(E-Mail Removed)> wrote in
>> >>> message news:OyHA0hb$(E-Mail Removed)...
>> >>>> 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" <(E-Mail Removed)> wrote in message
>> >>>> news:uY11n3a$(E-Mail Removed)...
>> >>>>> 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/ar...-controls.aspx
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> Teemu Keiski
>> >>>>> AspInsider, ASP.NET MVP
>> >>>>> http://blogs.aspadvice.com/joteke
>> >>>>> http://teemukeiski.net
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> "SandpointGuy" <(E-Mail Removed)> wrote in
>> >>>>> message news:(E-Mail Removed)...
>> >>>>>> 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
>> >>>>>
>> >>>>>
>> >>>>
>> >>>>
>> >>>
>> >>>
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: sending hidden values AND option values at the same time ? Jukka K. Korpela HTML 1 09-12-2006 02:32 PM
Repeater control - how to access contained control values? dotnw@hotmail.com ASP .Net 4 05-28-2005 07:54 AM
Replace Tab Key to Return Key (Enter Key) from Web Forms? M P ASP General 1 08-06-2004 08:32 AM
Please HELP! Need to access textbox control values within a repeater control Darren Smith ASP .Net 5 05-10-2004 03:37 PM



Advertisments