Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
HI Please see this code
Response.Write("<form name=forml action =die1.aspx method=get id=form1>")
Response.Write("<table>")
  Response.Write("<tr>")...
While (dr.Read())
Response.Write("<tr>")
Response.Write("<td>" + dr("XGENAME").ToString() + "</td><td>" + dr("EANAME").ToString() + "</td>")
Response.Write("<td>")
Response.Write("<input type='textbox' id ='fone'>")
Response.Write("</td>")
Response.Write("<td>")
Response.Write("<input type='textbox' id='fadd'>")
Response.Write("</td>")
Response.Write("<td>")
Response.Write("<input type =textbox id =flast>")
Response.Write("</td>")
Response.Write("<td>")
Response.Write("<input type =textbox id =dexp>")
Response.Write("</td>")
Response.Write("</tr>")
End While
orc.Dispose()
Response.Write("</table>")
Response.Write("<input type = submit value = submit>")
Response.Write("<center>")
Response.Write("</form>")
how to get the value of the textboxes in the action page
Posted

First, instead of doing all of those Response.Write calls, use a StringBuilder to build the entire output, and to set the text boxes, simply use the StringBuilder.AppendFormat() method, like so:

VB
Dim html As New StringBuilder("")
html.Append("<form name=\"forml\" action=\"die1.aspx\" method=\"get\" id=\"form1\">")
html.Append("<table>")
While (dr.Read())
    html.Append("<tr>")
    html.AppendFormat("<td>{0}</td><td>{1}", dr("XGENAME").ToString(), dr("EANAME").ToString())
    html.AppendFormat("<table><tbody><tr><td><input type=\"textbox\" id=\"fone\" text=\"{0}\" /></td></tr></tbody></table>", dr("FONE").ToString())
    html.AppendFormat("<table><tbody><tr><td><input type=\"textbox\" id=\"fadd\" text=\"{0}\" /></td></tr></tbody></table>", dr("FADD").ToString())
    html.AppendFormat("<table><tbody><tr><td><input type=\"textbox\" id=\"flast\" text=\"{0}\" /></td></tr></tbody></table>", dr("FLAST").ToString())
    html.AppendFormat("<table><tbody><tr><td><input type=\"textbox\" id=\"dexp\" text=\"{0}\" /></td></tr></tbody></table>", dr("DEXP").ToString())
    html.Append("</td></tr>")
End While
orc.Dispose()
html.Append("</table>")
html.Append("<input type=\"submit\" value=\"submit\">")
html.Append("</input></form>")
Response.Write(html)


That code is much cleaner and easier to maintain (not to mention much shorter).
 
Share this answer
 
v2
Comments
Vivek Krishnamurthy 28-Jun-11 9:55am    
Agree that its cleaner, easier and maintainable. But not answering the question.
fjdiewornncalwe 28-Jun-11 10:03am    
This does answer the question. The error is that quoting of attribute values is incorrect and potentially problematic. That being said, You need to escape your inner quotes, John. ( I have taken the liberty of doing that for you )
#realJSOP 28-Jun-11 11:08am    
Yeah, thanks - I forgot to escape the quotes.
BobJanova 28-Jun-11 11:45am    
In this case I agree that it is better this way, although the use of a StringBuilder does not make the code shorter, cleaner or easier to maintain (you are replacing a method call with another method call on a 1:1 basis and both are equally obvious). What StringBuilder gives you is performance, not code readability.

In cases where the processing within a loop could take a long time (not true here), it can make sense to build up one row (using a StringBuilder) and then use Response.Write and Response.Flush to stream the data to the client as it is created, instead of giving them a long wait while you calculate it.
If you are posting to another page, see http://msdn.microsoft.com/en-us/library/ms178139.aspx[^]
 
Share this answer
 
You have the id attribute but you are missing the name attribute (they can be the same). If you are posting to an action page, the values won't be in the form unless the form elements have the name attribute specified.

<input type="textbox" id="fone" name="fone"></input>


Cheers.
 
Share this answer
 
First, as MrJames pointed out, to get values in a form postback you need to set the name attribute, not id. (id is used by JavaScript, if you have none of that, you don't need to set it at all. It is allowed to have id and name be the same.)

If there is more than one row, you will be duplicating names – you should include some unique key from dr in the name.
 
Share this answer
 
single codes are missing in form tag.rectify that..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900