请更正此代码中的错误? [英] please correct the error in this code ?

查看:68
本文介绍了请更正此代码中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,请参见此代码

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

推荐答案

首先,不要执行所有这些Response.Write调用,而是使用StringBuilder构建整个输出并设置文本框,只需使用StringBuilder.AppendFormat()方法,如下所示:

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:

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).


如果要发布到另一个页面,请参见
If you are posting to another page, see http://msdn.microsoft.com/en-us/library/ms178139.aspx[^]


您具有id属性,但您丢失了名称属性(它们可以相同).如果要发布到操作页面,则除非表单元素指定了name属性,否则值将不在表单中.

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.


这篇关于请更正此代码中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆