Click here to Skip to main content
15,904,828 members

Comments by Member 13098156 (Top 2 by date)

Member 13098156 17-Feb-20 4:17am View    
Can you make both examples please?

In the meanwhile I have made some experimentations and in javascript the following lines work properly and they assign the value to the HiddenField1 placed into the .aspx page:

var id= "1";
$("#HiddenField1").val(id); //HiddenField1 is now "1"...it works!

In my case the issues are (to be a bit more precise):

1) In the code behind
string test = form1.HiddenField1.value does not work (error: HtmlForm does not contains a definition for HiddenField1)
2) In the code behind
string test = HiddenField1.Value seems to be accepted (no error messages) but test is always an empty string, despite the fact that $("#HiddenField1").val(id) is working properly

So...in a nutshell:
1) How can I access from code behind to
string test = HiddenField1.Value

2) if I have a method like this in the code behind
public string getState (string id)
{
string tempvalue = "";
if (state == "1"){tempvalue = "image1.png"}
if (state == "2"){tempvalue = "image2.png"}
return tempvalue;
}
how can I pass the value id to the method from the .aspx page?

In the .aspx page the statement
var id = 1;
var icon = "<%getState (id)%>";
gives the error "The name 'id' does not exist in the current context".

Hoping I have been clear, thanks in advance for your support.
Member 13098156 14-Feb-20 11:22am View    
Dear Karthik,
I have the same problem: could you please make an example about your answer?

what do you mean for "u will using form object to read the client controls value."


I have:


form id="form1" runat="server"

and

<asp:hiddenfield id="HiddenField1" runat="server" clientidmode="Static" validaterequestmode="Enabled" viewstatemode="Enabled">

How can i access it from code behind?

string test = form1.HiddenField1.value; does not work at all!

Regards