简体   繁体   English

.net ascx控件在回发时不保留值(mojoPortal)

[英].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.

相关问题 ASCX上的RadioButton在回发时无值 - RadioButton on ASCX no value on Postback ViewState [“ sample”]变量在复合控件中不保留回发值 - ViewState[“sample”] Variable not retaining value on postback in a composite control .ascx中的控件不会在回发时显示其新值 - Controls within .ascx are not displaying their new value on postback 启用ASP(.NET 4)ViewState的文字控件不能在PostBack上保留对HTML内容的更改 - ASP (.NET 4) ViewState enabled Literal control not retaining changes to HTML contents on PostBack 在用户控件 (.ascx) 中传递 &lt;%=value%&gt; - Passing <%=value%> in user control (.ascx) 如何在没有回发或重新加载页面的情况下加载.ascx 控件 in.aspx 页面 - How to load .ascx control in .aspx page with out postback or reloading the page Datagrid中的复选框保留VB.NET中回发时的检查值,但不保留C# - Checkbox within Datagrid retaining checked value on postback in VB.NET but not C# 在ASP.NET中回发后通过jQuery保留动态生成的HTML元素的值和状态 - Retaining the value and state of dynamically generated HTML elements via jQuery after Postback in ASP.NET 在回发中获取asp.net控件的旧值 - Getting the old value of a asp.net control on postback ASP.NET绑定ASCX中的属性不会在回发时更新 - Asp.net binding a property in ascx not updating on postback
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM