Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多视图-视图清除状态_C#_.net_View_Multiview - Fatal编程技术网

C# 多视图-视图清除状态

C# 多视图-视图清除状态,c#,.net,view,multiview,C#,.net,View,Multiview,提前感谢你的帮助 我正在使用c.net 我的网页上有两个视图包含在一个多视图中,两个视图都包含按钮 视图1 包含一个中继器/数据源和一个定制的“编辑”按钮,该按钮保存返回的每一行的ID 视图2 包含“更新”窗体和“更新”按钮。当用户按下更新按钮时,数据库中该特定行的信息将被更新 我认为问题在于视图2中的“更新”按钮 “更新”按钮后面的代码,我有一个if语句: protected void Page_Load(object sender, EventArgs e) {

提前感谢你的帮助

我正在使用c.net

我的网页上有两个视图包含在一个多视图中,两个视图都包含按钮

视图1

包含一个中继器/数据源和一个定制的“编辑”按钮,该按钮保存返回的每一行的ID

视图2

包含“更新”窗体和“更新”按钮。当用户按下更新按钮时,数据库中该特定行的信息将被更新

我认为问题在于视图2中的“更新”按钮

“更新”按钮后面的代码,我有一个if语句:

        protected void Page_Load(object sender, EventArgs e)
    {
        updateSuccessFailed.Visible = false;

        if (!Page.IsPostBack)
        {
            _multiView1.ActiveViewIndex = 0;
        }
    }   

protected void update_Click(object sender, EventArgs e)
{

_视图2

<asp:View ID="_view2" runat="server">      
    <div style="text-align:center" runat="server" id="notYetUpdated">
      <table border="0" cellspacing="1">
        <tr>
          <td style="text-align:left;">Name</td>
          <td style="text-align:left;"><asp:TextBox ID="updateName" MaxLength="60" runat="server" /></td>
        </tr>
        <tr>
          <td style="text-align:left;">Postcode</td>
          <td style="text-align:left;"><asp:TextBox ID="updatePropPostcode" MaxLength="60" runat="server" /></td>         
        </tr>         
      </table><br />              

      <asp:Button ID="updateVCancel" Text="Cancel" runat="server" onclick="cancel_Click" CssClass="standardButton" />
      <asp:Button ID="updateVConfirm" Text="Update" runat="server" onclick="update_Click" CssClass="standardButton" />
      <asp:HiddenField ID="vUpdateID" runat="server" />     
    </div> 

    <div style="text-align:center" runat="server" id="updateSuccessFailed">
      <p><asp:Label ID="updateMessage" runat="server" /></p>
      <asp:Button ID="updateBack" Text="Back To Start" runat="server" onclick="backToStart_Click" CssClass="standardButton" /> 
    </div>

  </asp:View>
谢谢


克莱尔:-

第四行应该是updateSuccessFailed.Visible=false;?

这是我的错误。我修改了代码,如下所示:

var Id = Convert.ToInt32((ID.Value)); 

tblV updateV = new tblV();        
updateV.vID = venueId;        
updateV.vame = updateName.ToString();        
updateV.vPostcode = updatePropPostcode.ToString();  

notYetUpdated.Visible = false;    
updateSuccessFailed.Visible = true; 

if (vRepos.Update(updateV))        
{                   
updateMessage.Text = "Updated.";        
}        
else        
{     
updateMessage.Text = "An error has occurred, please try again.";        
}

希望这对其他人有所帮助。

很抱歉误读了您的消息。这是写这个问题时的回复。我的代码是失败的。克莱尔,如果我理解了这个问题,我认为您应该将updateSuccessFailed.Visible to false设置为update\u Click函数。例如,在页面加载中,我添加了updateSuccessFailed.Visible=false然而,在我的页面加载中,当用户第二次进入视图2时,什么也没有显示。这可能是因为按钮被缓存了吗?我添加了更多的代码,这是否更好?我相信当我按下updateSuccessFailed div中的“back to start”按钮时会发生什么。它以某种方式存储了“Update”已按下“e”按钮。因此,当我通过_view1访问另一行的“编辑”按钮时,它会将我传递到_view2,但它已经认为“更新”按钮已按下,因此会直接进入更新点击事件。尝试将EnableViewState=False添加到更新确认按钮
    ViewState.Clear();
    ClearChildViewState();
var Id = Convert.ToInt32((ID.Value)); 

tblV updateV = new tblV();        
updateV.vID = venueId;        
updateV.vame = updateName.ToString();        
updateV.vPostcode = updatePropPostcode.ToString();  

notYetUpdated.Visible = false;    
updateSuccessFailed.Visible = true; 

if (vRepos.Update(updateV))        
{                   
updateMessage.Text = "Updated.";        
}        
else        
{     
updateMessage.Text = "An error has occurred, please try again.";        
}