问题:服务端赋值给服务器控件 hidenfiled
AddWorkStation.aspx.cs 代码片段:
if (allWorkstations.Count >= licenseType.MaximumWorkstations)
{
hidMessage.Value = "Lite Edition only allows you to add " + licenseType.MaximumWorkstations.ToString() + " workstaions in system!";
}
{
前端HTML代码片段:
1 <ComponentArt:PageView ID="workstationPageView1" runat="server">
2 <h3>
3 <%=Resources.Base.WorkstationName%></h3>
4 <div>
5 <%--value="<%=Resources.Base.Add%>"--%>
6 <asp:TextBox ID="workstationName" runat="server" MaxLength="50" Width="300px" CssClass="required"></asp:TextBox>
7 <input id="byNameOk" type="button" runat="server" value="<%$Resources:Base,Add %>"
8 onclick="byNameCallbackClick()" style="width: 80px" />
9 <input type="button" value="<%=Resources.Base.Close%>" onclick="closePopupDialog(true)"
10 style="width: 80px" />
11 </div>
12 <br />
13 <div>
14 <ComponentArt:CallBack ID="byNameCallback" runat="server">
15 <Content>
16
17 </Content>
18 <ClientEvents>
19 <CallbackComplete EventHandler="byNameCallback_Complete" />
20 <CallbackError EventHandler="byNameCallback_Error" />
21 </ClientEvents>
22 </ComponentArt:CallBack>
23 </div>
24 <br />
25 <div id="msg" class="MessageBottomDivStyle" style="overflow: auto; width: 95%; height: 150px">
26 </div>
27 <div>
28 <asp:HiddenField ID="hidMessage" runat="server" />
29 </div>
30 </ComponentArt:PageView>
2 <h3>
前端JS代码片段
View Code
1 function byNameCallback_Complete(sender, args) {
2 //var temMsg = $("#hidMessage").val();
3 // var tempMessage = document.getElementById("hidMessage").value;
4 var temMsg = document.getElementById('<%= hidMessage.ClientID %>').value;
5
6 //var tempMessage = $("#<%=hidMessage.ClientID%>").val();
7 if (errorMsg == "") {
8 if (temMsg == "") {
9 $(msgDiv).toggleClass("successMsg");
10 $(msgDiv).html("<%=Resources.Base.Changessaved%>");
11 }
12 else {
13 $(msgDiv).toggleClass("failMsg");
14
15 $(msgDiv).html("<%=Resources.Base.OperationFailed %> " + "<br/>" + temMsg);
16 }
17 }
18 else {
19 $(msgDiv).toggleClass("failMsg");
20
21 $(msgDiv).html("<%=Resources.Base.OperationFailed %> " + "<br/>" + errorMsg);
22
23 }
24 window.document.getElementById("byNameOk").disabled = false;
25 }
2 //var temMsg = $("#hidMessage").val();
前台 temMsg 取不到值
解决:
在后台AddWorkStation.aspx.cs 代码片段加入 hidMessage.RenderControl(e.Output);
View Code
1 if (allWorkstations.Count >= licenseType.MaximumWorkstations)
2 {
3 hidMessage.Value = "Lite Edition only allows you to add " + licenseType.MaximumWorkstations.ToString() + " workstaions in system!";
4 hidMessage.RenderControl(e.Output);
5 }
2 {
原因:由于使用了ComponentArt的Callback 控件,前台页面没有刷新,也就没有从后台取得数据,所以需要使用 hidMessage.RenderControl(e.Output) 将值发回给页面。