[英].net ascx control not retaining value on postback (mojoPortal)
I'm making a custom module for mojoPortal CMS which needs to allow the client to add an affiliate into the database. 我正在为mojoPortal CMS创建一个自定义模块,该模块需要允许客户端将会员添加到数据库中。 As far as I can tell, this requires creating a .ascx file and then installing that using the administration toolbar in the Web interface to get it to a point where I can put it into a page, as http://www.mojoportal.com/hello-world-developer-quick-start.aspx . 据我所知,这需要创建一个.ascx文件,然后使用Web界面中的管理工具栏进行安装,以使其可以放置到页面中,如http://www.mojoportal。 com / hello-world-developer-quick-start.aspx 。
The form is simple enough, but the values in the text boxes just stay empty when I submit, though the file upload works fine. 表单很简单,但是在我提交时,文本框中的值仍然为空,尽管文件上传效果很好。 The code: 编码:
<asp:Label ID="Label1" runat="server" Text="Company Name" AssociatedControlID="CompanyName">
</asp:Label>
<asp:TextBox ID="CompanyName" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Company Description" AssociatedControlID="CompanyDescription"></asp:Label>
<asp:TextBox ID="CompanyDescription" TextMode="MultiLine" runat="server"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Company Logo" AssociatedControlID="CompanyLogo"></asp:Label>
<asp:FileUpload ID="CompanyLogo" runat="server" />
<asp:Button ID="SubmitButton" runat="server" Text="Add Affiliate" />
EnableViewState for the page and the controls is enabled 页面和控件的EnableViewState已启用
The text box is not set to ReadOnly, and there is no funky JavaScript dynamically modifying elements (at least, I didn't set any). 文本框未设置为ReadOnly,并且没有时髦的JavaScript动态修改元素(至少,我没有设置任何元素)。
I can work around this by using HTML elements, and get the values using Request.Form. 我可以通过使用HTML元素来解决此问题,并使用Request.Form获取值。 The information is actually there, I can see it in the Request.Form, but I would have to get that by something like Request.Form[CompanyName.ClientId.Replace("_","$")] or Request.Form[6] which both seem very messy and IIRC aren't really the way things are supposed to roll in .NET. 信息实际上在那里,我可以在Request.Form中看到它,但是我必须通过诸如Request.Form [CompanyName.ClientId.Replace(“ _”,“ $”)]]或Request.Form [ 6]看起来都非常混乱,而且IIRC并不是.NET中应该发生的事情。 Besides, having worked until 3 last night, I really want to know what the answer is now! 此外,昨晚工作到3点,我真的很想知道答案是什么!
Any thoughts anyone? 有任何想法吗?
What I had done was not created a click event for the button, relying on the fact that it was posting to the server (like I would in PHP). 我所做的并不是根据按钮是否已发布到服务器这一事实来创建按钮的click事件(就像我在PHP中那样)。 Oops! 糟糕! When I added a click event, then the text boxes retained their value when I was within that method. 当我添加click事件时,当我处于该方法中时,文本框将保留其值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.