473,378 Members | 1,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Javascript controls

I got the following JS function:

<script language="javascript" type="text/javascript">
function addUser()
{
var users = document.getElementById('users');
var hidden = document.createElement('input');
hidden.value = 'foo';
users.appendChild(hidden);
var i =0;
for(var node = users.firstChild;node !=null; node =
node.nextSibling)
{
if(node.nodeType != 1) //input
continue;
node.id = 'project.Users['+i+'].Id';
i++;
}
}
</script>

And the following form:
<form id="form1" runat="server">
<div id="users">
<input id="Button1" type="button" value="Add User"
onclick="javascript:addUser();" />
</div>
<asp:TextBox ID="PostBackValues" runat="server" Height="225px"
TextMode="MultiLine" Width="596px"></asp:TextBox><br />
<asp:Button ID="submit" runat="server" Text="submit"
OnClick="submit_Click" /><br />
</form>
I open the page, click on the Add User button a couple of times, and
then submit.
In my code behind file I have:
protected void submit_Click(object sender, EventArgs e)
{
foreach (string key in Request.Params.AllKeys)
{
PostBackValues.Text += string.Format(" {0}: {1}\r\n", key,
Request.Params[key]);
}
}

But I can't see the values I set using JS. In fact, when checking with
Fiddler, I can see that they aren't added to the POST varaibles at all.
Any ideas what this is?

Feb 27 '06 #1
4 1179
Have you tried adding name attributes to the
controls?

<ay****@gmail.com> wrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
I got the following JS function:

<script language="javascript" type="text/javascript">
function addUser()
{
var users = document.getElementById('users');
var hidden = document.createElement('input');
hidden.value = 'foo';
users.appendChild(hidden);
var i =0;
for(var node = users.firstChild;node !=null; node =
node.nextSibling)
{
if(node.nodeType != 1) //input
continue;
node.id = 'project.Users['+i+'].Id';
i++;
}
}
</script>

And the following form:
<form id="form1" runat="server">
<div id="users">
<input id="Button1" type="button" value="Add User"
onclick="javascript:addUser();" />
</div>
<asp:TextBox ID="PostBackValues" runat="server" Height="225px"
TextMode="MultiLine" Width="596px"></asp:TextBox><br />
<asp:Button ID="submit" runat="server" Text="submit"
OnClick="submit_Click" /><br />
</form>
I open the page, click on the Add User button a couple of times, and
then submit.
In my code behind file I have:
protected void submit_Click(object sender, EventArgs e)
{
foreach (string key in Request.Params.AllKeys)
{
PostBackValues.Text += string.Format(" {0}: {1}\r\n", key,
Request.Params[key]);
}
}

But I can't see the values I set using JS. In fact, when checking with
Fiddler, I can see that they aren't added to the POST varaibles at all.
Any ideas what this is?

Feb 28 '06 #2
On Mon, 27 Feb 2006 15:09:32 -0800, ayende wrote:
I got the following JS function:

<script language="javascript" type="text/javascript">
function addUser()
{
var users = document.getElementById('users');
var hidden = document.createElement('input');
hidden.value = 'foo';
users.appendChild(hidden);
var i =0;
for(var node = users.firstChild;node !=null; node =
node.nextSibling)
{
if(node.nodeType != 1) //input
continue;
node.id = 'project.Users['+i+'].Id';
i++;
}
}
</script>

And the following form:
<form id="form1" runat="server">
<div id="users">
<input id="Button1" type="button" value="Add User"
onclick="javascript:addUser();" />
</div>
<asp:TextBox ID="PostBackValues" runat="server" Height="225px"
TextMode="MultiLine" Width="596px"></asp:TextBox><br />
<asp:Button ID="submit" runat="server" Text="submit"
OnClick="submit_Click" /><br />
</form>
I open the page, click on the Add User button a couple of times, and
then submit.
In my code behind file I have:
protected void submit_Click(object sender, EventArgs e)
{
foreach (string key in Request.Params.AllKeys)
{
PostBackValues.Text += string.Format(" {0}: {1}\r\n", key,
Request.Params[key]);
}
}

But I can't see the values I set using JS. In fact, when checking with
Fiddler, I can see that they aren't added to the POST varaibles at all.
Any ideas what this is?


The javascript is not creating the input elements properly or perhaps not
adding them to the DOM. I notice that they don' have a name or id!
Otherwise, you should see the values in the Params object. If the users
added all have the same name, you will see them as a comma-list of values.

Feb 28 '06 #3
With the name attirbute it works, thanks.

Feb 28 '06 #4
Their id is set, but their name wasn't, when I added the name, it
appeared.

Feb 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.