Hidden Field value set in Javascript

F

fatima.issawi

Hello,

I am trying to set the value of a hidden field in Javacript in my
UserControl. I need to access the value in the code-behind.

For some reason, the value of the hidden field never gets set on the
client even though it is executing that function. Can anyone help me
figure out why? I am new to this, so please excuse if this seems
elementary.

I have my code snippets below.

Thank you in advance,
Fatima

From my code-behind:

protected void SaveSelected(object blah)
{
// These values are always "Test" - the initial value of
hdnSelected
string test = hdnSelected.Value;
string test2 = blah.ToString();
}

From my user control:


<asp:HiddenField ID="hdnSelected" runat="server" Value="Test" />

<script language="javascript" type="text/javascript">

var grid;
var SelectedIndexesPerPage = {};
var inputName;

function UpdateSelectedRows(pageIndex)
{
var selRows = grid.MasterTableView.SelectedRows;
var result = "";
if(typeof(selRows[0]) != "undefined")
{
result = selRows[0].ItemIndex.toString();
}
var i=1;
while(typeof(selRows) != "undefined")
{
result = result + "," + selRows.ItemIndex.toString();
i=i+1;
}
SelectedIndexesPerPage[pageIndex] = result;

SaveHashValues();


var shidden = document.getElementById("<%=hdnSelected.ClientID
%>");
shidden.Value = result;
shidden.Value = "blah blah blah";
hdnSelected.Value = "nonononon";
// Testing saving in session variable
<% SaveSelected(hdnSelected.Value); %>


}
 
B

bruce barker

the dom is case sensitive (and is always lowercase), its:

shidden.value = 'xxxx';

not sure the point of <% SaveSelected(hdnSelected.Value); %>, it should
be tied to page_load

-- bruce (sqlwork.com)

Hello,

I am trying to set the value of a hidden field in Javacript in my
UserControl. I need to access the value in the code-behind.

For some reason, the value of the hidden field never gets set on the
client even though it is executing that function. Can anyone help me
figure out why? I am new to this, so please excuse if this seems
elementary.

I have my code snippets below.

Thank you in advance,
Fatima

From my code-behind:

protected void SaveSelected(object blah)
{
// These values are always "Test" - the initial value of
hdnSelected
string test = hdnSelected.Value;
string test2 = blah.ToString();
}

From my user control:


<asp:HiddenField ID="hdnSelected" runat="server" Value="Test" />

<script language="javascript" type="text/javascript">

var grid;
var SelectedIndexesPerPage = {};
var inputName;

function UpdateSelectedRows(pageIndex)
{
var selRows = grid.MasterTableView.SelectedRows;
var result = "";
if(typeof(selRows[0]) != "undefined")
{
result = selRows[0].ItemIndex.toString();
}
var i=1;
while(typeof(selRows) != "undefined")
{
result = result + "," + selRows.ItemIndex.toString();
i=i+1;
}
SelectedIndexesPerPage[pageIndex] = result;

SaveHashValues();


var shidden = document.getElementById("<%=hdnSelected.ClientID
%>");
shidden.Value = result;
shidden.Value = "blah blah blah";
hdnSelected.Value = "nonononon";
// Testing saving in session variable
<% SaveSelected(hdnSelected.Value); %>


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top