Click here to Skip to main content
12,950,090 members (51,378 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi everyone,
I am using with c#. I m getting problem in retrieve hidden field value.

<input type="hidden" id="hdn_perchher_id_<%# Container.ItemIndex %>" value='<%# Eval("user_id") %>' />  

So anyone tell me how to get value or id of above hidden field in cs file.

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                Repeater Repeater2 = (Repeater)e.Item.FindControl("rpt_Common_Perchher");
                HiddenField hd = (HiddenField)e.Item.FindControl("hdn_perchher_id_<%# Container.ItemIndex %>");
                cls_PerchhConnection perchhconnection = new cls_PerchhConnection();
                DataTable dt_common_perchhers = new DataTable();
                int user_id1 = Convert.ToInt32(Session["perchh_uid"]);
                dt_common_perchhers = perchhconnection.Proc_GetCommonPerchhers(user_id1, 57);
                Repeater2.DataSource = dt_common_perchhers;

In above code i got hd = null in place of null it will be show some value of control.
Please sort it out.

Thanx in Advance.
Posted 9-Jan-13 22:14pm
Updated 9-Jan-13 22:45pm
Suvabrata Roy 10-Jan-13 4:17am
What kind of problem...?
faisal23 10-Jan-13 4:18am
I want to get value of this hidden field which is dynamic and bind in repeater..
Suvabrata Roy 10-Jan-13 4:22am
R you trying to get the value from code behind or in javascript?
faisal23 10-Jan-13 4:25am
in cs file i have to use its value as a parameter for other function.
If i got the idea how to get id of this control i able find its value.
sarathsprakash 10-Jan-13 4:25am
do you want to retrieve the value in the next form after submitting
faisal23 10-Jan-13 4:29am
No it is on same form. I have 2 repeaters in parent repeater this hidden field retrieved dynamically in nested repeater i want the value of this hidden field.
So i want how to retrieve id or value of this control for passing parameter to one of the function.
faisal23 10-Jan-13 4:35am
You are giving me solution but its not working for me you dont see my problem it is binded dynamically and its id "hdn_perchher_id_<%# Container.ItemIndex %>" so how i can do this. IT
sarathsprakash 10-Jan-13 4:38am
just go through the below solution and reply
Rate this: bad
Please Sign up or sign in to vote.

Solution 4


You did use rounge procedure for getting value of hiddefield with in repeater

in simple way I provide you :-

<input type="hidden" id="Rizwan" value='<%# Eval("user_id") %>' />  


HiddenField hd = (HiddenField)e.Item.FindControl("Rizwan");

I hope your Problem will resolve if not Please give me your Comment.
faisal23 10-Jan-13 5:27am
Hi I update my code according to you but i got error. Hidden variable is null.
"System.NullReferenceException: Object reference not set to an instance of an object"
rizwan muhammed khan gouri 10-Jan-13 5:50am
can you give me your code
rizwan muhammed khan gouri 10-Jan-13 5:50am
runat="server" also used
manoj kumar choubey 11-Jan-13 2:07am
Very Nice Rizwan muhammed khan gouri
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

For getting the the value in the cs file

public partial class _Default : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e)
        String a = HiddenField1.Value;
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


If you want to get it in your cs page then transfer using Javascript through Query string, Ajax Call call or via post.


Select the current selection value to a hidden field (Sever Control) and access it in your cs page, for multiple value separate using comma.
faisal23 10-Jan-13 4:55am
It is not server control.
Suvabrata Roy 10-Jan-13 4:58am
Yes, I know insert another hidden field (Server Control) and on selection of your row you will set the value to that server hidden filed via Javascript and now get it back on server.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

<asp:hiddenfield id="hdnEmailID" runat="server" xmlns:asp="#unknown" />

<pre lang="cs">protected void LinkGroupSummary_Click(object sender, EventArgs e)
            hdnEmailID.Value = this.EmailList;

if (Page.PreviousPage != null)
                        HiddenField MyHiddenValue = (HiddenField)Page.PreviousPage.FindControl("hdnEmailID");
                        if (MyHiddenValue != null)
                            string email = MyHiddenValue.Value;
faisal23 10-Jan-13 4:56am
First of all it is not server control and second is that it is dynamic bind in repeater means contains many values.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,749
CHill60 3,380
Maciej Los 2,953
Jochen Arndt 1,935
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100