473,790 Members | 2,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading input field from innerhtml span

Nez
Help needed!
Hello, I have looked everywhere for a solution to my problem and
this is pretty much my last resource. I have created a table in a span
with the innerhtml command in my code behind. In this table I have
created textbox html input fields. Now I need to allow the user to
change the value in the textfield, and compare it to the old value I
have stored in a cookie.

Problem is, because the textfield was created in the code behide I
can't simple referer to it value as QTY1.text.

HTML EXAMPLE

<form id="Cart" method="post" runat="server">
<table id="border">
<table id="Body">
<TABLE id="Table1" >
<SPAN id="Span1"
runat="server"> </SPAN></table></table></table>.....

with a bunch of code all around and inbetween,

CODE BEHIND

look something like this.

'============== ============Som eCode
here=========== ==============
While y <> x
y = y + 1
tempCookieName = "Item" & y
If Not Request.Cookies (tempCookieName ) Is Nothing Then

Dim cItem As HttpCookie =
Request.Cookies (tempCookieName )
Dim varProductDescr iption As String
Dim varProductCost As Double
Dim varCategoryID As Integer

'============== ============Som eCode
here=========== ==============

SQLConnection.O pen()
MyCommand.Execu teNonQuery()
varProductDescr iption =
HttpUtility.Htm lDecode(MyComma nd.Parameters(" @Description"). Value)

varProductCost = MyCommand.Param eters("@Price") .Value
varProductCost = varProductCost * cItem.Values("Q ")
varCategoryID =
MyCommand.Param eters("@Categor yID").Value
SQLConnection.C lose()

'============== ============Som eCode
here=========== ==============

lblSubTotal.Tex t = String.Format(" {0:###,##0.00}" ,
lblSubTotal.Tex t + varProductCost)
Span1.InnerHtml += "<TR><TD width='255'><P
align='left'><F ONT face='Helvetica ' color='#ff0000' >"
Span1.InnerHtml += "Cart Items</FONT></P></TD><TD
align='center' width='72'>"
Span1.InnerHtml += "<FONT face='Helvetica '
color='#ff0000' >QTY</FONT></TD><TD
align='center'> Options</TD><TD>Price</TD>"
Span1.InnerHtml += "</TR><TR><TD vAlign='top'
width='255'><A HREF='../Store/ProductDetails. aspx?ProductID= " &
cItem.Values("P ") & "&CategoryI D=" & varCategoryID & "&View=1'>" &
varProductDescr iption & "</A>"
Span1.InnerHtml += "</asp:HyperLink></TD><TD
vAlign='top' align='center' width='72'>"
Span1.InnerHtml += "<asp:TextB ox id='QTY2'
ReadOnly='False ' >" & cItem.Values("Q ") & "</asp:TextBox></TD><TD
vAlign='top'>"
Span1.InnerHtml += "<P><A HREF='cart.aspx '>Save for
Later</A><BR><A HREF='cart.aspx ?Delete=" & y & "'>Delete</A>"
Span1.InnerHtml += "</P></TD><TD vAlign='top'><P >$" &
varProductCost & "</P><br><asp:Labe l id='lblItem" & y & "'
runat='server' ForeColor='Whit e'>" & y & "</asp:Label></TD></TR>"
End If

End While
'============== ============ SomeCode Here
=============== ==========
Anyway, there's no problems displaying what I want, the textfields
are created and they are given a unique id of "QTY#".
I simply want to read the value that has been changed in the textfield.
Compare it to the number if used to create the text field and change
it if it is different.

I have tried everything to get this to work, tried using javascript,
Which I did get to discover the value for me but then I could not use
it to change the asp cookie, leaving me once again without a solution.
I have tried using the "Findcontro l" function but without any luck.
Anything useful is most appreciated....
Tony Philip
to********@gmai l.com

May 10 '06 #1
7 2609
You can always do this the old skool way and iterate the Request.Form
collection

http://msdn2.microsoft.com/en-us/lib...uest.form.aspx

but um... looking at your code, have you thought about using an
asp:Repeater? Then you can either use FindControl on each element of
the repeater's items collection or, better yet, add an OnChange event
to an asp:TextBox and handle your changes from there.

Is there a reason you're using InnerHtml like this?

May 10 '06 #2
Couldn't you add runat="server" to the textfield to make it accessible
server-side? I did this with a registration page to hide TR's that the
user didn't need to fill out.

May 10 '06 #3
Nez
I have thought about using a repeater. I am storing a table in
cookies.
I can loop through the cookies and write that to the screen but I don't
know how to write that data to a table or dataset or somthing that can
be bound to the repeater.
Cookie Sample
ITEM1 P = Product name
ITEM1 PD = Product Decription
ITEM1 Q = Quantity

ITEM2 P = Product name
ITEM2 PD = Product Decription
ITEM2 Q = Quantity

and so on. If you know a way to write these to a table of somesort in
memory that I can then bind that would be great... Do you know how or
what read the cookies to that I can then Bind to repeater?
Thanks for the help so far... We are on the same page. I just don't
know how to get the cookies to bind.

May 11 '06 #4
Nez
I tried using the runat="server" no luck. I had it there orignially.
I've made so many changes and tried so many things. Keep them comming
though. I really appreciate the help..

May 11 '06 #5
If you're telling me that you've got values like Request.Cookies["ITEM1
P"], Request.Cookies["ITEM1 PD"] ...

then you'd want to parse your cookie structure first unless anyone has
any tricks up their sleeve.

Probably the best way to do that with that format would be to knock up
a regex that tests for (ITEM\d+) so you can get a list of the item
names before you start reading values out of your cookie.

If you want to use a cookie, you might find it easier with a more
structured format... You could always serialize a strongly typed list
of products to some format and store that instead. The .Net framework
has excellent support for serializing objects to Xml or binary data.

Then you can do

// deserialize shopping cart held in the cookie value "Cart".
// You can always encrypt this with, for example, the user's password
ProductList shoppingCart = GetCartFromCook ie(Request.Cook ies["Cart"]);

// now you're back and object oriented and the rest is a doddle.
myRepeater.Data Source = shoppingCart;
myRepeater.Data Bind();
I'm sure some clever MVP will give you manifold reasons why this is a
bad idea but it seems eminently sensible to me. That's why I'm a Least
Valued Professional.

Why a cookie and not in Session state or a database?

May 12 '06 #6
Nez
Thanks for the response,
I was trying not to use Session states, and writing to the Database as
to keep down the Server resources. I do final right this information
to the database but only after I know they are going to purchase.

I can read out the information from the cookies to the database,
adding one Item at a time. Is there a Variable that will hold the
table in memory which I can then bind. I would be able to build the
Table variable the same way I right to the DB; One Item row at a time.
Once it was stored in the Variable I could then perhaps bind it. An
Array will not hold a table and Hashtable will not bind to a repeater.
I'm truly at a loss here. Can I not create a Dataset, and populate it
with the data? Then just bind the Dataset?

Is there a way to create an empty dataset and then insert each row of
the table through some kind of add row to dataset statement?

May 13 '06 #7
You have to add an ID attribute along with runat="server" to
programmaticall y access the control.

May 22 '06 #8

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

Similar topics

12
4913
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same question twice! Here it is: I am having problems reading the value of a text Node. I think it has to do with the fact that the text is in a <span> tag. I have a table and in each <td> I have text + a checkbox. I want to retreive the text next to the...
8
1468
by: Rose Chambers | last post by:
How can I insert preformatted text from a file on the web server into a table's cell? And then swapped the text in response to an onClick event. Something like this......... <table> <tr><td> <img name="swap_grph" src="http://www.mydomain.com/graphs/piechart1.jpg"> </tr></td><tr><td>
4
1820
by: Anders Nielsen | last post by:
Hi :-) I'm currently working with innerHTML , but it is giving me some problems with " and '. Basically (there is also some ASP involved), my problem looks like this: I would like to, dynamically, insert the following html into a table cell: <span id="soeskende5slet" style="position: absolute; right: 70px; cursor:hand; text-decoration:underline;" onClick="soeskendeSlet('5','Anders
5
5292
by: gimme_this_gimme_that | last post by:
I'd like to create my own version of google suggest GS. If you haven't seen GS check it out at : http://www.google.com/webhp?complete=1&hl=en I've reviewed several AJAX write-ups on the internet and understand the issues around passing and fetching data from the client to the server. Well, at least as it's described in various tutorials.
1
4023
by: spolsky | last post by:
try the the following code with Opera 9.01 (Windows). when clicked slightly faster than normal clicking, the toggler checkbox and other checkboxes displays differently although event method works fine to update the checkboxes. there is not any problem with IE 6 or FireFox 1.5. also, i used the double click event method to see if its the source but that does not help even. Opera 9.01 seems to be slow at updating checkboxes visually. am i...
4
4515
by: sicapitan | last post by:
I have this code snippet: updateProps snippet: if (mycheckbox.checked == '1') ? $('mycheckbox').checked = true : $('mycheckbox').checked = false; content = $('mydiv').innerHTML;
3
5644
by: Ralph | last post by:
Hi I have small function to generate my form controls: function buildInput(sType, vValue, vId, sName, sLabel){ var oInput = null; var oLabel = document.createElement('label'); var oCont = document.createElement('span'); var oText = document.createTextNode(sLabel); oInput = document.createElement('<input type="'+ sType +'" name="'+ sName +'" />');
3
4825
by: cbradio | last post by:
Hi, I am having trouble developing a form in a restricted environment. My sample code is found below my message (sorry I don't have a URL). Basically, without a doctype, the form displays properly with 3px padding around each form field, and no overlap. But the doctype changes the box model, I am told, and so the padding is added to the 100% width, leading to overlap and poor presentation. Unfortunately, I'm forced to use the doctype due to...
2
2541
by: Ed Jay | last post by:
I'm dynamically creating several form input elements: mValue = integer constant; for(var j = 0; j < mValue; j++) { target = "imgCn"+ j; eName = "myFile"; eName = eName+jj; document.getElementById(target).innerHTML = "<input type = 'file' name="+eName+" value=''>text"; }
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.