DropDown indexChanged事件和按钮onClick事件正在清除我的textBoxes [英] DropDown indexChanged event and button onClick event are clearing my textBoxes
问题描述
你好,为什么当我从我的dropDownList中选择一个项目或者当我点击一个按钮清除我的textBoxes?
这是我的ASP代码
<% @ Page 标题 = Réparation 语言 = C# MasterPageFile = 〜/ TP / MasterPageTP.master AutoEventWireup = true CodeFile = ModifRep.aspx.cs 继承 = TP_ModifRep %>
< asp:Content ID = Content2 ContentPlaceHolderID = ContentPlaceHolder1 Runat = 服务器 >
< div id = 内容 >
< br / >
< br / >
< h2 > Matérielsenéparations< / h2 >
< ; asp:Panel ID = Panel1 runat = server align = center >
< table style = border-color:#000099;身高:918px; width:688px border = 1 >
< ; tr >
< td >
< asp:标签 ID = Label18 < span class =code-attribute> runat = server 文字 = Diagnostiquedupréstatire > < / asp:标签 >
< / td >
< td >
< asp:TextBox ID = txtSuivi runat = server CssClas s = TextBox
< span class =code-attribute> 高度 = 94px 宽度 = 288px < span class =code-attribute> TextMode = MultiLin e > < / asp :TextBox >
< / td >
< / tr >
< tr >
< td >
< asp:标签 ID = Label20 runat = 服务器 文字 = Statut > < / asp:标签 >
< / td >
< td >
< ; asp:DropDownList ID = cmbStatut runat = server CssClass = Combobox
高度 = 32px 宽度 = 170px AutoPostBack < span class =code-keyword> = True AppendDataBoundItems = true
onselectedindexchanged = < span class =code-keyword> cmbStatut_SelectedIndexChanged >
< span class =code-keyword>< / asp:DropDownList >
< br / >
< < span class =code-leadattribute> asp:Label ID = lblErrorSta runat = 服务器 ForeColor = 红色
文字 = Veuillez saisir le statut 可见 = 错误 > < span class =code-keyword>< / asp:Label >
< / td >
< / tr >
< tr >
< td >
< asp:标签 ID = Label19 runat = server 文字 = 日期deécéptiondumatériel > < / asp:Label >
&l t; / td >
< td >
< asp:TextBox ID = txtDateReception runat = server CssClass = TextBox
高度 = 25px 宽度 = 162px > < / asp:TextBox >
< asp:CalendarExtender ID = txtDateReception_CalendarExtender runat = server
< span class =code-attribute>已启用 = True TargetControlID = txtDateReception >
< / asp:CalendarExtender >
< / td >
< < span class =code-leadattribute> / tr >
< tr >
< td >
< asp:Label ID = Label21 runat = server 文字 = Nouveau服务标签 > < / asp:标签 >
< / td >
< td >
< asp :TextBox ID = txtNvSt runat = server CssClass = TextBox 高度 = 25px
宽度 = 162px > < / asp:TextBox >
< asp:L abel ID = lblST runat = server 文字 = 标签 > < / asp:Label >
< / td >
< / tr >
< / table >
< asp:Button ID = btnValider runat = 服务器 CssClass = blueButton
文本 = Valider onclick = < span class =code-keyword> btnValider_Click / >
< / asp:Panel >
这是我的btnValider代码
protected void btnValider_Click( object sender,EventArgs e)
{
if (cmbStatut.SelectedIndex == 2 )
{ if ( string .IsNullOrEmpty(txtNvSt.Text))
{
con.charger( 更新物资集修复= NULL其中serviceTag =' + txtServiceTag.Text + ',假跨度>);
会话[ ST] = txtNvSt.Text;
Response.Redirect( NouveauMAt.aspx);
}
else
{
con.charger( 插入Stocker值('1',' + txtServiceTag.Text + '), false );
}
}
其他 if (cmbStatut .SelectedIndex == 3 )
{
con.charger( 插入Stocker值('4',' + txtServiceTag.Text + ), false );
Response.Redirect( StockHS.aspx);
}
}
首先,它测试dropDownList(cmbStatut)的选定索引,然后测试txtNvSt是否为空。如果它不为空,则必须检索txtNv.Text中的值并将其放入会话中,然后将其重定向到特定页面。
当我进行调试时,我发现txtNvSt.text =以及其他textBoxes。
同样的事情发生了当我从DropDownList中选择另一个项目时,会触发autopostBack并清除所有textBoxs
感谢您的帮助
引用:如果它不为空,则必须检索txtNv.Text中的值并将其放入会话中,然后将其重定向到特定页面。
但代码是相反的。如下所示...
if (! 串跨度> .IsNullOrEmpty(txtNvSt.Text)
hello, Why when I chose an item from my dropDownList or when I click on a button clears my textBoxes ??
here is my ASP Code
<%@ Page Title="Réparation" Language="C#" MasterPageFile="~/TP/MasterPageTP.master" AutoEventWireup="true" CodeFile="ModifRep.aspx.cs" Inherits="TP_ModifRep" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="content">
<br />
<br />
<h2>Matériels en réparations</h2>
<asp:Panel ID="Panel1" runat="server" align="center">
<table style="border-color: #000099; height: 918px; width: 688px" border="1">
<tr>
<td>
<asp:Label ID="Label18" runat="server" Text="Diagnostique du préstatire"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtSuivi" runat="server" CssClass="TextBox"
Height="94px" Width="288px" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label20" runat="server" Text="Statut"></asp:Label>
</td>
<td>
<asp:DropDownList ID="cmbStatut" runat="server" CssClass="Combobox"
Height="32px" Width="170px" AutoPostBack="True" AppendDataBoundItems="true"
onselectedindexchanged="cmbStatut_SelectedIndexChanged" >
</asp:DropDownList>
<br />
<asp:Label ID="lblErrorSta" runat="server" ForeColor="Red"
Text="Veuillez saisir le statut" Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label19" runat="server" Text="Date de récéption du matériel"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtDateReception" runat="server" CssClass="TextBox"
Height="25px" Width="162px"></asp:TextBox>
<asp:CalendarExtender ID="txtDateReception_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtDateReception">
</asp:CalendarExtender>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label21" runat="server" Text="Nouveau service tag"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtNvSt" runat="server" CssClass="TextBox" Height="25px"
Width="162px"></asp:TextBox>
<asp:Label ID="lblST" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
<asp:Button ID="btnValider" runat="server" CssClass="blueButton"
Text="Valider" onclick="btnValider_Click" />
</asp:Panel>
Here is my btnValider Code
protected void btnValider_Click(object sender, EventArgs e)
{
if (cmbStatut.SelectedIndex==2)
{if (string.IsNullOrEmpty(txtNvSt.Text))
{
con.charger("update Materiel set reparation= NULL where serviceTag='" + txtServiceTag.Text + "'", false);
Session["ST"] = txtNvSt.Text;
Response.Redirect("NouveauMAt.aspx");
}
else
{
con.charger("insert into Stocker values('1', '" + txtServiceTag.Text + "')", false);
}
}
else if (cmbStatut.SelectedIndex == 3)
{
con.charger("insert into Stocker values('4', '" + txtServiceTag.Text + "')", false);
Response.Redirect("StockHS.aspx");
}
}
At first it tests the selected index of the dropDownList (cmbStatut), and then it tests if the txtNvSt is empty or not. If it's not empty it has to retrieve the value in the txtNv.Text and put it in a session, after that it redirects me to the specific page.
When I did a debug, I found that the txtNvSt.text="" as well as other textBoxes.
The same thing happends when I chose another item from my DropDownList, it fires an autopostBack and clears all textBoxs
Thank you for your help
Quote:If it's not empty it has to retrieve the value in the txtNv.Text and put it in a session, after that it redirects me to the specific page.
But the code is the reverse. Do like below...
if(!string.IsNullOrEmpty(txtNvSt.Text)
这篇关于DropDown indexChanged事件和按钮onClick事件正在清除我的textBoxes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!