how to set hidden field value at run time

Posted by Bhavna81 under Regular Expressions on 12/14/2009 | Views : 15204 | Status : [Member] | Replies : 2
Hello Experts,

here is my design,
[code]
<form id="form1" runat="server">
<table border="3">
<% ArrayList no = (ArrayList)Session["srno"];
ArrayList nm = (ArrayList)Session["Name"];
for (int i = 0; i < no.Count; i++)
{ %>
<tr>
<td>
<%Response.Write(no[i]); %>
</td>
<td>
<%Response.Write(nm[i]); %>
</td>

<td>
<%-- '<%#Eval("no[i]")%>'--%>
<asp:HiddenField ID="hdnedit" runat="server" Value=<%# Eval("no[i]").ToString()%> />
<asp:Button ID="btnEdit12" runat="server" Text="Edit" onclick="btnEdit1_Click" />
</td>
<td>
<asp:Button ID="btnDelete12" runat="server" Text="Delete" />
</td>
</tr>
<%} %>
<tr>
<td colspan="4">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</form>
[/code]


My question is how can i set the value of hidden field


<asp:HiddenField ID="hdnedit" runat="server" Value=<%# Eval("no[i]").ToString()%> />

at code behind i set TextBox1.Text = hdnedit.Value;

but its not working.....

how can i????

thanks.




Responses

Posted by: Vuyiswamb on: 12/14/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day

You wrote :  My question is how can i set the value of hidden field 


but in this code you are not setting the Value of a Hidden Field but you are setting a Value of a textbox

TextBox1.Text = hdnedit.Value;


to set a Value of a hidden Field should the other way around like this


hdnedit.Value = TextBox1.Text;



Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Bhavna81, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 12/14/2009 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
If you use Server side HiddenField, you cant do Eval.

If you want to Eval you need to use Client side Input control.

Use Like this :

<input type="hidden" value="<%=yourtext%> />" />


One thing I am very uncertain, why do you use ASP style of coding still in .NET, you can use the flavour of .NET by using asp:Repeater to repeat rather than writing Server tags all over your design.

Anyways, I hope this will help you.
Cheers.


www.abhisheksur.com

Bhavna81, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response