使用 javascript 提交 ASP.NET 表单 - 未提交文本框值
我有一个用 ASP (C#) 编写的动态表单。在 page_load 中,我添加了要与其他对象一起提交的文本框。
该表单通过 javascript 与标签一起提交。
HyperLink btnBuy = new HyperLink();
btnBuy.CssClass = "btnLinkBuy btnLinkCheckoutGreen";
btnBuy.Attributes.Add("onmouseover", "GreenMouseOver()");
btnBuy.Attributes.Add("onmouseout", "GreenMouseOut()");
btnBuy.Attributes.Add("onclick", "javascript:postback()");
btnBuy.NavigateUrl = "#";
pnlVisaIcons.Controls.Add(btnBuy);
脚本位于
function postback() {
document.getElementById("checkoutForm").submit();
}
page_load 事件中,我正在检查是否 IsPostBack,如果是,我调用处理提交的数据的函数。但是,当我检查控制器时,它们是空的。就像回发删除所有数据
有什么想法吗?
I have a dynamic form written in ASP (C#). In the page_load I am adding the text box I want to submit along other objects.
The form is submitted with a tag through javascript.
HyperLink btnBuy = new HyperLink();
btnBuy.CssClass = "btnLinkBuy btnLinkCheckoutGreen";
btnBuy.Attributes.Add("onmouseover", "GreenMouseOver()");
btnBuy.Attributes.Add("onmouseout", "GreenMouseOut()");
btnBuy.Attributes.Add("onclick", "javascript:postback()");
btnBuy.NavigateUrl = "#";
pnlVisaIcons.Controls.Add(btnBuy);
and the script is
function postback() {
document.getElementById("checkoutForm").submit();
}
in the page_load event I am checking if IsPostBack and if so I call the function which handles the data submitted. However when I am checking the controllers they are empty. Like the post back deleted all the data
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在
PreInit
上添加动态控件,还必须在每次回发时添加动态控件。ASP.NET 页面生命周期概述
You need to add dynamic controls on
PreInit
, also you have to add the dynamic control(s) on each postback.ASP.NET Page Life Cycle Overview