aspx文件控件的赋值?

hkwlk 2007-10-22 10:52:03
单位从另一网页传进来和日期取服务器日期,
如何把以上的值付给runat="server" 的两个input控件?

基本内容如下:
<%
UserName = Request.QueryString("UserName")
str_date = DateTime.Today.ToString("yyyy-MM-dd")
%>
<form id="form1" method="post" runat="server" enctype="multipart/form-data">
<table align="center">
<tr>
<td style="width: 526px">单位:<input runat="server" id="station" type="text" style="text-align:center; width: 144px;" /></td>
</tr>
<tr>
<td style="width: 526px">日期<input runat="server" id="date1" type="text" style="text-align:center; width: 144px;" /></td>
</tr>
<tr>
<td style="width: 526px">新闻标题:  <input id="title" runat="server" type="text" style="width: 390px" />
</td>
</tr>
<tr>
<td style="width: 526px">新闻来源:  <input id="source" runat="server" type="text" style="width: 390px" />
</td>
</tr>
<tr>
<td style="height: 129px; width: 526px;">
新闻内容:<br />
<textarea id="contest" runat="server" style="width: 507px; height: 175px" ></textarea>
</td>
</tr>
<tr>
<td style="height: 30px; width: 526px;">图像文件(可选):<input runat="server" id="fUpLoadImage" style="width: 344px; height: 22px" type="file" />
</td>
</tr>
<tr>
<td height="58" colspan="2" align="center">
<input runat="server" id="btnSave" style="width: 97px; height: 29px" type="submit" value="上 传" />     
<input runat="server" id="Reset1" style="width: 101px; height: 29px" type="reset" value="重 置" /></td>

</tr>
</table>
</form>
...全文
206 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hnwlk 2007-10-24
  • 打赏
  • 举报
回复
自己搞定:
放在Protected Sub Page_Load(.....)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

UserName = Request.QueryString("UserName")
UserPass = Request.QueryString("UserPass")

str_date = DateTime.Today.ToString("yyyy-MM-dd")
date1.Text = str_date
station.Text = UserName
End Sub
hkwlk 2007-10-23
  • 打赏
  • 举报
回复
没成功
hnwlk 2007-10-23
  • 打赏
  • 举报
回复
自己再顶
  • 打赏
  • 举报
回复
input加runat="server",能不能直接用TextBox?
xray2005 2007-10-22
  • 打赏
  • 举报
回复
单位:<input runat="server" id="station" type="text" style="text-align:center; width: 144px;" / >

在.cs代码里写:
this.station.value=Request.QueryString["传过来的参数"];


日期 <input runat="server" id="date1" type="text" style="text-align:center; width: 144px;" / >


在.cs代码里写:
this.date1.value=System.DateTime.Now.ToString();
hkwlk 2007-10-22
  • 打赏
  • 举报
回复
而且在已后的提交中要得到这两个值,所以必须考虑 runat="server" 或者使用另外的方法
hkwlk 2007-10-22
  • 打赏
  • 举报
回复
to wuhan_dotnet你的方法是可以,但是我的是加上runat="server"的input,结果就出错,无法实现:
<input runat="server" type="text1" text = " <%=DateTime.Now.ToShortDateString()% >" 获取当地时间
<input runat="server" type="text2" text = " <%=Request.QueryString[""].Tostring()% >" 获取传的值
wuhan_dotnet 2007-10-22
  • 打赏
  • 举报
回复
<input type="text1" text = "<%=DateTime.Now.ToShortDateString()%>" 获取当地时间
<input type="text2" text = "<%=Request.QueryString[""].Tostring()%>" 获取传的值
这样就行了``
hkwlk 2007-10-22
  • 打赏
  • 举报
回复
up
hkwlk 2007-10-22
  • 打赏
  • 举报
回复
up
hkwlk 2007-10-22
  • 打赏
  • 举报
回复
to publina :
在文件test.aspx.vb里的定义和赋值如下:
Protected UserName As String
Protected str_date As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
UserName = Request.QueryString("UserName")
str_date = System.DateTime.Today.ToString("yyyy-MM-dd")
date1.value = str_date
station.value = UserName
End Sub

在test.aspx里的控件部分如下:
<form id="form1" method="post" runat="server" enctype="multipart/form-data" >
<table align="center" >
<tr >
<td style="width: 526px" >单位: <input runat="server" id="station" type="text" style="text-align:center; width: 144px;" / > </td >
</tr >
<tr >
<td style="width: 526px" >日期 <input runat="server" id="date1" type="text" style="text-align:center; width: 144px;" / > </td >
</tr >
<tr >
<td style="width: 526px" >新闻标题:   <input id="title" runat="server" type="text" style="width: 390px" / >
</td >
</tr >
<tr >
<td style="width: 526px" >新闻来源:   <input id="source" runat="server" type="text" style="width: 390px" / >
</td >
</tr >
<tr >
<td style="height: 129px; width: 526px;" >
新闻内容: <br / >
<textarea id="contest" runat="server" style="width: 507px; height: 175px" > </textarea >
</td >
</tr >
<tr >
<td style="height: 30px; width: 526px;" >图像文件(可选): <input runat="server" id="fUpLoadImage" style="width: 344px; height: 22px" type="file" / >
</td >
</tr >
<tr >
<td height="58" colspan="2" align="center" >
<input runat="server" id="btnSave" style="width: 97px; height: 29px" type="submit" value="上 传" / >     
<input runat="server" id="Reset1" style="width: 101px; height: 29px" type="reset" value="重 置" / > </td >

</tr >
</table >
</form >

运行结果:
<input runat="server" id="date1" ...和<input runat="server" id="station"...
显示为空没有赋值成功
publina 2007-10-22
  • 打赏
  • 举报
回复

//CS文件
protected string UserName = Request.QueryString("UserName")
protected string str_date = DateTime.Today.ToString("yyyy-MM-dd")
date1.Value = str_date ;
........


<form id="form1" method="post" runat="server" enctype="multipart/form-data" >
<table align="center" >
<tr >
<td style="width: 526px" >单位: <input runat="server" id="station" type="text" style="text-align:center; width: 144px;" / > </td >
</tr >
<tr >
<td style="width: 526px" >日期 <input runat="server" id="date1" type="text" style="text-align:center; width: 144px;" / > </td >
</tr >
<tr >
<td style="width: 526px" >新闻标题:   <input id="title" runat="server" type="text" style="width: 390px" / >
</td >
</tr >
<tr >
<td style="width: 526px" >新闻来源:   <input id="source" runat="server" type="text" style="width: 390px" / >
</td >
</tr >
<tr >
<td style="height: 129px; width: 526px;" >
新闻内容: <br / >
<textarea id="contest" runat="server" style="width: 507px; height: 175px" > </textarea >
</td >
</tr >
<tr >
<td style="height: 30px; width: 526px;" >图像文件(可选): <input runat="server" id="fUpLoadImage" style="width: 344px; height: 22px" type="file" / >
</td >
</tr >
<tr >
<td height="58" colspan="2" align="center" >
<input runat="server" id="btnSave" style="width: 97px; height: 29px" type="submit" value="上 传" / >     
<input runat="server" id="Reset1" style="width: 101px; height: 29px" type="reset" value="重 置" / > </td >

</tr >
</table >
</form >
hkwlk 2007-10-22
  • 打赏
  • 举报
回复
to xray2005 在.vb里加时,前面如何定义input控件?

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧