回发时不保留表单字段
我正在使用 EPiServer 开发一个网站。我有一个自我提交的表格。 提交时,我检查是否缺少任何字段。如果是,则显示错误消息。
问题是我的字段在提交时被重置。
我可以使用 jQuery 来检查这一点,但我没有。我正在从后面的代码中检查这一点。
我尝试过设置 EnableViewState=true
几个地方,但没有运气。
这是我的代码的一部分:
<asp:Content ID="Content3" ContentPlaceHolderID="RightContentPlaceHolder" runat="server">
<asp:Panel ID="panelComplaint" runat="server">
<li>
<h3>Postnummer*</h3>
<input id="senderPostCode" name="postCode" type="text" size="20" enableviewstate="true" />
<asp:Label runat="server" id="lblPostCode" CssClass="missingField" Text="Mangler tekst" Visible="false" />
</li>
<li>
<h3>Post sted*</h3>
<input id="senderCity" name="city" type="text" size="100" />
<asp:Label runat="server" id="lblCity" CssClass="missingField" Text="Mangler tekst" Visible="false" />
</li>
<li>
<div class="spacer10px"></div>
<button type="submit" name="Send" >Send me</button>
</li>
</asp:Panel>
</asp:Content>
为了保留表单字段,我需要做什么?
I'm developing a website using EPiServer. I have a form which submits to itself.
On submit, I check if there are any fields missing. If yes, then error message is shown.
The problem is that my fields are reset when submitted.
I could check this using jQuery, but I'm not. I'm cheking this from code behind.
I've tried setting EnableViewState=true
sevceral places, but no luck.
Here's part of my code:
<asp:Content ID="Content3" ContentPlaceHolderID="RightContentPlaceHolder" runat="server">
<asp:Panel ID="panelComplaint" runat="server">
<li>
<h3>Postnummer*</h3>
<input id="senderPostCode" name="postCode" type="text" size="20" enableviewstate="true" />
<asp:Label runat="server" id="lblPostCode" CssClass="missingField" Text="Mangler tekst" Visible="false" />
</li>
<li>
<h3>Post sted*</h3>
<input id="senderCity" name="city" type="text" size="100" />
<asp:Label runat="server" id="lblCity" CssClass="missingField" Text="Mangler tekst" Visible="false" />
</li>
<li>
<div class="spacer10px"></div>
<button type="submit" name="Send" >Send me</button>
</li>
</asp:Panel>
</asp:Content>
What do I need to do, in order to retain form fields?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过将
runat="server"
添加到输入字段?据我所知,这是确保 asp.net 正确往返数据所必需的。我不确定 EPiServer 是否有任何特定的东西会使情况有所不同。enableviewstate
属性,除非它特定于 EPiServer,否则实际上不会执行任何操作。如果 ASP.net 混合 ID 存在问题,请考虑升级到 .NET 4.0(如果可以的话),因为这为您提供了控制 ID 修改方式的方法。如果没有,您可以尝试在页面中放置一个友好的翻译,然后您可以通过 JQuery 访问该页面,例如:
也就是说,引用“getSenderPostCode()”意味着您可以跳过使用 JQuery 获取引用的步骤到它,所以以下内容将起作用:
通过将
runat="server"
添加到您的控件,您就不需要使用Request.Form["senderPostCode"].ToString()< /code> 要访问该字段的内容,您可以直接访问它:
Have you tried adding
runat="server"
to the input fields? As far as I'm aware, this is needed to ensure that asp.net round-trips data properly. I'm not sure if there's anything specific to EPiServer that would make that differ.The
enableviewstate
attribute, unless it's specific to EPiServer, won't actually be doing anything.If having the ID mashed up by ASP.net is a problem, consider upgrading to .NET 4.0, if you can, as this provides ways for you to control how the ID's are modified. If not, you could try placing a friendly translation into the page that you can then access via JQuery, for example:
That said, having "getSenderPostCode()" to reference would mean that you could probably skip the step with JQuery of getting a reference to it, so the following would work:
By adding
runat="server"
to your controls you then wouldn't need to useRequest.Form["senderPostCode"].ToString()
to access the content of that field, you could instead access it directly: