此页面代码在vs.net 2003 没有问题,我把转成 vs.2005确出现: 不能取出用js修改了textbox的值,当页面已经显示用js修改的值:  请看页面JS的:DepartSelect()ASPX:
%@ Page language="c#" Inherits="FrameWork.Popedom.UsersEdit" CodeFile="UsersEdit.aspx.cs" CodeFileBaseClass="BasePageClass.BasePage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>UsersEdit</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="../CommCss/Style.css" type="text/css" rel="stylesheet">
<script language="javascript">
    function ReturnBack()
    {
     if (document.getElementById("Tb_UserID").value=="")
        location.href ="QueryUserPopedom.aspx?pID=0&pDisplayType=0"
     else
        location.href ="QueryUserPopedom.aspx?pID="+document.getElementById("Tb_UserID").value+"&pDisplayType=1"
     }
     
    function DepartSelect()
            {
            /* var RetObj;
             RetObj = window.showModalDialog("../CommForm/CheRadioDept.aspx?pGetType=last@pChooseDept="+document.getElementById("Tb_DepartNo").value,window,"dialogHeight:400px;dialogWidth:407px;center:Yes;Help:No;Resizable:No;Status:Yes;Scroll:auto;Status:no;");
             if(RetObj==null)
             {
                return false;
             }
             else
             {
                    var RetString =RetObj;
                    var RetArr = RetString.split(",");
                document.all.Tb_DepartNo.value=RetArr[0];
        document.all.Tb_DepartName.value=RetArr[1];
        return true;
     }*/
                document.all.Tb_DepartNo.value="111111";
        document.all.Tb_DepartName.value="22222";
             }
             
           </script>
</HEAD>
<body oncontextmenu="return false" leftMargin="0" topMargin="0">
<noscript>
<iframe src="*"></iframe>
</noscript><form method="post" runat="server">
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td colSpan="5">
<table height="19" cellSpacing="0" cellPadding="0" width="100%" bgColor="#f1f1f1" border="0">
<tr>
<td style="FONT-WEIGHT: bold; COLOR: navy">&nbsp;<IMG src="../FwImage/FrmEdit.gif">系统用户信息</td>
<td>
<asp:label id="Lab_UserID" runat="server" Visible="False"></asp:label>
<asp:label id="Lab_DisplayType" runat="server" Visible="False"></asp:label></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colSpan="4">
<TABLE id="Table1" height="100%" cellSpacing="1" cellPadding="0" width="100%" bgColor="#D4E1E9"
border="0">
<TR bgColor="#ffffff">
<TD style="WIDTH: 74px; HEIGHT: 25px" bgColor="#E7EBEF">
<DIV style="COLOR: #3366ff" align="right">用户代码&nbsp;</DIV>
</TD>
<TD style="WIDTH: 453px; HEIGHT: 30px" vAlign="middle" bgColor="white">
<TABLE height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR bgColor="#ffffff">
<TD style="WIDTH: 74px; HEIGHT: 25px" bgColor="#E7EBEF">
<DIV style="COLOR: #3366ff" align="right">部门代码&nbsp;</DIV>
</TD>
<TD style="WIDTH: 453px; HEIGHT: 30px" vAlign="middle" bgColor="white">
<TABLE height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR>
<TD vAlign="middle" width="110">&nbsp;
<asp:textbox id="Tb_DepartNo" runat="server" Width="90px" BorderStyle="Groove" ReadOnly="True"></asp:textbox></TD>
<TD vAlign="middle" width="80" bgColor="#E7EBEF">
<DIV style="COLOR: #3366ff" align="right">部门名称 &nbsp;</DIV>
</TD>
<TD vAlign="middle">&nbsp;
<asp:textbox id="Tb_DepartName" runat="server" Width="230px" BorderStyle="Groove" ReadOnly="True"></asp:textbox><INPUT class="ButtonCss" onclick="javascript:DepartSelect()" type="button" value="..."
name="Btn_Department" id="Btn_DepartName"></TD>
</TR>
</table></HTML>
----------------------------------------------------------------------------
cs:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using BasePageClass;
using GcPopedom.PdmClassStructuralClass;namespace FrameWork.Popedom
{
/// <summary>
/// UsersEdit 的摘要说明。
/// </summary>
public partial class UsersEdit : BasePage
{

private UserListInf dUserList = new UserListInf();
protected void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
........
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{     }
#endregion protected void Btn_Save_Click(object sender, System.EventArgs e)
{
            Page.Response.Write("<script>alert('" + Tb_DepartNo.Text + "$$$" + Tb_DepartName.Text + "')</script>");
}
}
}点击Btn_DepartName按钮通过JS修改了textbox的值,在点击Btn_Save按钮:弹出提示信息不是:"111111$222222" 而是:"$" 
真奇怪

解决方案 »

  1.   

    BasePage:代码
    using System;
    using System.Web;
    using System.Configuration;
    using System.Web.SessionState;
    using GcPopedom.PopedomClass;
    using ComFunction;namespace BasePageClass
    {
    /// <summary>
    /// Class 的摘要说明。
    /// </summary>
    public class BasePage:System.Web.UI.Page
    {
    public FunctionClass FunClass =new FunctionClass();
    public PopedomService PdmClass =new PopedomService(); #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load  += new System.EventHandler(this.Page_Load);
                this.Error += new System.EventHandler(this.Page_Error);
    }
    #endregion private void Page_Load(object sender, System.EventArgs e)
    {
    PdmClass.PageLoadPopedom(Session["UserID"].ToString());
    } private void Page_Error(object sender,System.EventArgs e)
    {
    string errMessage = Server.GetLastError().Message;
    errMessage+="&pPath="+Request.Path;
    Server.ClearError();
    Response.Redirect("/"+ConfigurationSettings.AppSettings["ProgramName"]+"/FrameWork/CommForm/AccessError.aspx?pError="+errMessage);
    }
    }
    }
      

  2.   

    的确比较奇怪?
        试试用Page.RegisterStartupScript("","<script language=javascript>alert('"+Tb_DepartNo.Text +"$$$"+ Tb_DepartName.Text  +"')</script>");
    看看.点击 Btn_Save跟踪看看Tb_DepartNo.Text ,Tb_DepartName.Text是否有值
      

  3.   

    <asp:textbox id="Tb_DepartNo" runat="server" Width="90px" BorderStyle="Groove" ReadOnly="True"></asp:textbox>readonly 了。2.0里客户端就改不了值了。http://community.csdn.net/Expert/TopicView3.asp?id=4952204
      

  4.   

    在ASP.NET 2.0里,如果TextBox服务器控件的ReadOnly属性设置为True,在服务器端将得不到TextBox服务器控件的值,这是ASP.NET 2.0为了安全性考虑,在服务器端不处理只读文本框。
    要解决这个问题,需要使用别的方法来实现,举例如下。
    C#:
    <%@ Page Language="C#" %>
    <script runat="server">
      protected void Button1_Click(object sender, EventArgs e)
      {
        Response.Write(TextBox1.Text);
      }
      protected void Page_Load(object sender, EventArgs e)
      {
        TextBox1.Attributes.Add("readonly", "true");
      }
    </script><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
      <title>TextBox 控件的 ReadOnly 属性</title>
    </head>
    <body>
      <form id="form1" runat="server">
        <div>
          <asp:TextBox ID="TextBox1" runat="server">ok</asp:TextBox>&nbsp;
          <input id="Button2" type="button" value="修改数据为 孟宪会"
           onclick="TextBox1.value='孟宪会'" />
          <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
            Text="提交" /></div>
      </form>
    </body>
    </html>
    VB.NET:
    <%@ Page Language="VB" %>
    <script runat="server">
      Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Write(TextBox1.Text)
      End Sub
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        TextBox1.Attributes.Add("readonly", "true")
      End Sub
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
      <title>TextBox 控件的 ReadOnly 属性</title>
    </head>
    <body>
      <form id="form1" runat="server">
        <div>
          <asp:TextBox ID="TextBox1" runat="server">ok</asp:TextBox>&nbsp;
          <input id="Button2" type="button" value="修改数据为 孟宪会"
           onclick="TextBox1.value='孟宪会'" />
          <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
            Text="提交" /></div>
      </form>
    </body>
    </html>