关于在页面中嵌套了用户控件后,在客户端用js调用服务器控件无法取得其值的问题
在一个aspx页面中嵌套了一个用户控件, 且在该页面中服务器控件,代码如下:
1<%@ Page Language="C#" AutoEventWireup="true" Theme="default" CodeFile="OrderShow.aspx.cs" Inherits="OrderShow" %>
2
3<%@ Register Src="BytUserControl/ShowOrder.ascx" TagName="ShowOrder" TagPrefix="uc12" %>
4<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6<html xmlns="http://www.w3.org/1999/xhtml" >
7<head runat="server">
8<title>产品中心</title>
9</head>
10<body>
11<form id="form1" runat="server"><%--style="display:block"--%>
12 <uc12:ShowOrder ID="ShowOrder1" runat="server" />
13<Div ID="dail" style="visibility:hidden">
14 <h3 style="width:496px;">添加订单</h3>
15 <table border="1" style="width: 496px">
16 <tr>
17 <td style="width: 100px; height: 15px">
18 下单名:</td>
19 <td align="left" style="width: 150px; height: 15px">
20 <asp:TextBox ID="txtOrderName" runat="server"></asp:TextBox></td>
21 <td align="left" style="width: 113px; height: 15px">
22 成色:</td>
23 <td align="left" style="width: 202px; height: 15px">
24 <asp:DropDownList ID="ddChekColer" runat="server" Width="128px" DataTextField="MaterialName" DataValueField="MaterialID">
25 </asp:DropDownList></td>
26 </tr>
27 <tr>
28 <td style="width: 100px; height: 24px;">
29 字印:</td>
30 <td align="left" style="width: 150px; height: 24px;">
31 <asp:TextBox ID="txtWordIndia" runat="server"></asp:TextBox></td>
32 <td align="left" style="width: 113px; height: 24px;">
33 要求出单日期:</td>
34 <td align="left" style="width: 202px; height: 24px;">
35 <cc1:CustomDatePicker id="txtOutOrderDate" CssClass="inputa" runat="server" Width="120px"></cc1:CustomDatePicker>
36 </td>
37 </tr>
38 <tr>
39 <td style="width: 100px; height: 22px">
40 备注:</td>
41 <td align="left" style="height: 22px" colspan="3">
42 <asp:TextBox ID="txgRemarks" runat="server" Width="392px"></asp:TextBox></td>
43 </tr>
44 <tr><td colspan="2" style="height: 14px">
45 </td>
46 <td colspan="1" style="height: 14px; width: 113px;">
47 <input id="Button3" style="width: 120px" type="button" value="添加" onclick="AddOrder()" /></td>
48 <td colspan="1" style="height: 14px; width: 202px;">
49 <input id="Button4" style="width: 112px" type="button" value="取消" onclick="HddenDiv()"/></td>
50 </tr></table>
51 </Div>
52</form>
53 </body>
54</html>
55
在47行中的 AddOrder() 方法alert()出来的值居然为空,代码如下:2
3<%@ Register Src="BytUserControl/ShowOrder.ascx" TagName="ShowOrder" TagPrefix="uc12" %>
4<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6<html xmlns="http://www.w3.org/1999/xhtml" >
7<head runat="server">
8<title>产品中心</title>
9</head>
10<body>
11<form id="form1" runat="server"><%--style="display:block"--%>
12 <uc12:ShowOrder ID="ShowOrder1" runat="server" />
13<Div ID="dail" style="visibility:hidden">
14 <h3 style="width:496px;">添加订单</h3>
15 <table border="1" style="width: 496px">
16 <tr>
17 <td style="width: 100px; height: 15px">
18 下单名:</td>
19 <td align="left" style="width: 150px; height: 15px">
20 <asp:TextBox ID="txtOrderName" runat="server"></asp:TextBox></td>
21 <td align="left" style="width: 113px; height: 15px">
22 成色:</td>
23 <td align="left" style="width: 202px; height: 15px">
24 <asp:DropDownList ID="ddChekColer" runat="server" Width="128px" DataTextField="MaterialName" DataValueField="MaterialID">
25 </asp:DropDownList></td>
26 </tr>
27 <tr>
28 <td style="width: 100px; height: 24px;">
29 字印:</td>
30 <td align="left" style="width: 150px; height: 24px;">
31 <asp:TextBox ID="txtWordIndia" runat="server"></asp:TextBox></td>
32 <td align="left" style="width: 113px; height: 24px;">
33 要求出单日期:</td>
34 <td align="left" style="width: 202px; height: 24px;">
35 <cc1:CustomDatePicker id="txtOutOrderDate" CssClass="inputa" runat="server" Width="120px"></cc1:CustomDatePicker>
36 </td>
37 </tr>
38 <tr>
39 <td style="width: 100px; height: 22px">
40 备注:</td>
41 <td align="left" style="height: 22px" colspan="3">
42 <asp:TextBox ID="txgRemarks" runat="server" Width="392px"></asp:TextBox></td>
43 </tr>
44 <tr><td colspan="2" style="height: 14px">
45 </td>
46 <td colspan="1" style="height: 14px; width: 113px;">
47 <input id="Button3" style="width: 120px" type="button" value="添加" onclick="AddOrder()" /></td>
48 <td colspan="1" style="height: 14px; width: 202px;">
49 <input id="Button4" style="width: 112px" type="button" value="取消" onclick="HddenDiv()"/></td>
50 </tr></table>
51 </Div>
52</form>
53 </body>
54</html>
55
1<script language="javascript">
2 function AddOrder()
3 {
4
5 var Remarks =document.getElementById("txgRemarks").value;
6 var WordIndia=document.getElementById("txtWordIndia").value;
7 var OrderName=document.getElementById("txtOrderName").value;
8
9 alert(Remarks+WordIndia+OrderName);
10
11
12 }
13</script>
在调试中无意发现只取控件ID问题就解决了,代码如下:2 function AddOrder()
3 {
4
5 var Remarks =document.getElementById("txgRemarks").value;
6 var WordIndia=document.getElementById("txtWordIndia").value;
7 var OrderName=document.getElementById("txtOrderName").value;
8
9 alert(Remarks+WordIndia+OrderName);
10
11
12 }
13</script>
1function AddOrder()
2 {
3
4 var Remarks =txgRemarks.value;
5
6 var WordIndia=txtWordIndia.value;
7
8 var OrderName=txtOrderName.value;
9
10 alert(Remarks+WordIndia+OrderName);
11
12
13 }
原因不明!
2 {
3
4 var Remarks =txgRemarks.value;
5
6 var WordIndia=txtWordIndia.value;
7
8 var OrderName=txtOrderName.value;
9
10 alert(Remarks+WordIndia+OrderName);
11
12
13 }