转换为母版页
我有 3 个 ASP.Net 页面。每个都有一个表单、一个提交按钮和一个 Javascript submit
函数,用于验证文本框数据。
当我将这3个页面转换为母版页/内容页时,合并三个表单和提交功能的最佳方法是什么?
提前致谢!
I have 3 ASP.Net pages. Each one has a form, a submit button, and a Javascript submit
function, which it validates textbox data.
When I convert these 3 pages to Master Page/Content Page, what is the best way to merge three forms and submit functions?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
仅仅因为多个页面有表单并不意味着表单处理逻辑应该重构到母版页中。在定义表单的代码隐藏位置通常是表单处理逻辑所在的最佳位置。
Just because multiple pages have forms doesn't mean the form processing logic should be refactored into a master page. In the codebehind of wherever a form is defined is typically the best place for the form processing logic to go.
如果它们仅在表单内容上有所不同,则将其他所有内容放入母版页中,并将表单单独放入每个内容页中。
我会将每个表单的 Submit 方法保留在其内容页面的代码隐藏中,因为这些方法将彼此独立。
为了整洁起见,您可以将它们全部链接到同一个 javascript 验证文件,并调用不同的验证方法
,并让每个表单的“提交”按钮调用其自己的方法,例如
If they only differ by the contents of the form, then put everything else into the Master page, and the form alone into each Content Page.
I'd leave the Submit method for each form in it's Content page's code-behind, because these will be independent of each other.
You could have them all link to the same javascript validation file, for neatness, and call different validation methods
and have each form's Submit button call its own method, e.g.
我将创建一个 Web 用户控件来封装提交按钮、Javascript 提交函数和文本框的 UI 和功能。
然后,如果需要,您可以将控件添加到母版页。
I would create a web user control to encapsulate the UI and functionality of the submit button, Javascript submit function, and textbox.
Then you could add the control to a master page if you wanted to.
您可以将
submit
函数放在母版页中,并使内容页定义submit
函数使用的每页函数或变量。如需更具体的建议,请发布更多详细信息。
You can put the
submit
function in the master page and make the content pages define per-page functions or variables that thesubmit
function uses.For more specific advice, please post more details.