Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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#_Asp.net_Textbox_Postback - Fatal编程技术网

C# 回发后删除文本框数据

C# 回发后删除文本框数据,c#,asp.net,textbox,postback,C#,Asp.net,Textbox,Postback,我有一个文本框的问题,它不能在回发时保留数据,在我的代码中,我有asp.cs事件btnGuardar按钮正在通过存储过程插入它们并进行回发,这里的问题是,当你回发除了放置文本框标题新闻以外的其他数据字段时,我不明白的是,在我的pc上,使用windows pro 8.1和最新版本的iis在本地工作,但这个错误并没有为我保存texbox的价值,它发生在windows server 2012中,并且发生在我正在做的系统中的几个texbox其他页面中 <%@ Page Title="" Langu

我有一个文本框的问题,它不能在回发时保留数据,在我的代码中,我有asp.cs事件btnGuardar按钮正在通过存储过程插入它们并进行回发,这里的问题是,当你回发除了放置文本框标题新闻以外的其他数据字段时,我不明白的是,在我的pc上,使用windows pro 8.1和最新版本的iis在本地工作,但这个错误并没有为我保存texbox的价值,它发生在windows server 2012中,并且发生在我正在做的系统中的几个texbox其他页面中

<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.master" AutoEventWireup="true" CodeFile="AltaEvento.aspx.cs" Inherits="Apartados_Administrar_Eventos_AltaEvento" EnableViewState="true" %>
<%@ Register TagPrefix="cc" Namespace="Winthusiasm.HtmlEditor" Assembly="Winthusiasm.HtmlEditor" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <style>
        .pickerEventosAdmin
        {
            width: 600px;
        }

    </style>
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div class="other-box yellow-box ui-corner-all">
        <div class="cont tooltip ui-corner-all"
            title="Para mayor informaci&oacute;n: - Comun&iacute;quese con el administrador - Consulte la documentaci&oacute;n del m&oacute;dulo">
            <h3>Alta y Edici&oacute;n de eventos</h3>
            <p>
                Genere nuevos eventos y edite anteriores. Un evento puede contener im&aacute;genes, v&iacute;deos, y documentos.
            </p>
            <p>
                Puede agregar las im&aacute;genes, v&iacute;deos, y documentos despu&eacute;s de que guarde el evento.
            </p>
        </div>
    </div>
   <%-- <h1><span style="color:red; font-size:20px"> Se está trabajando con esta pantalla. Aún no puede dar de alta eventos</span></h1><br />--%>

    <asp:Label ID="lblMensaje" ClientIDMode="Static" runat="server"></asp:Label>
    <div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all form-container">
        <div class="portlet-header ui-widget-header">Formulario de creaci&oacute;n y edici&oacute;n de eventos</div>
        <div class="portlet-content">
            <ul class="form-ul">     
                <li>
                    <label runat="server" for="<%=txtTituloEvento.ClientID%>">* Titulo del evento:</label>
                    <asp:TextBox  ID="txtTituloEvento" runat="server" CssClass="text  large"></asp:TextBox>
                </li>
                <li class="clearfix"></li>
                <li>
                    <label for="<%=Descripcion.ClientID%>">* Informaci&oacute;n del evento:</label>
                    <cc:HtmlEditor ID="Descripcion" runat="server" Height="100px" Width="750px"
                        ToggleMode="None" BackColor="White" BorderColor="WhiteSmoke"
                        BorderStyle="Solid" ButtonMouseOverColor="193, 210, 238"
                        DialogBackColor="GhostWhite" DialogBorderColor="Black"
                        DialogButtonBarColor="SlateGray" DialogForeColor="Black"
                        DialogHeadingColor="208, 208, 208" DialogHeadingTextColor="127, 157, 185"
                        DialogSelectedTabColor="127, 157, 185" DialogSelectedTabTextColor="White"
                        DialogTableColor="238, 238, 238" DialogUnselectedTabColor="208, 208, 208"
                        EditorBackColor="248, 248, 248" EditorBorderColor="217, 217, 217"
                        EditorInnerBorderColor="GradientInactiveCaption"
                        NoToolstripBackgroundImage="True" TabBackColor="208, 208, 208"
                        ToolbarColor="208, 208, 208"
                        Toolbars="Bold,Italic,Underline:Left,Center,Right,Justify|OrderedList,BulletedList|Subscript,Superscript,Link" />
                </li>
                <li class="clearfix"></li>
                <li>
                    <br />


                            <asp:CheckBox ID="chkPublicar" AutoPostBack="true" runat="server" /> Publicar

                     <%--   <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="chkPublicar" EventName="CheckedChanged" />
                        </Triggers>--%>

                </li>
                <li class="clearfix"></li>                                
                <li>
                    <br />
                    <asp:Button ID="btnGuardar" runat="server" Text="Guardar" CssClass="submitBtn" OnClick="btnGuardar_Click" />
                    <br /><br />
                </li>                
            </ul>
        </div>
    </div>
    <br />

如何,将Textbox.text值保存在会话变量中,并在页面加载时重新绑定它。检查类似问题。

我认为您必须自己保存数据并重新加载,当我回家后,我可以查看一个旧项目,希望此帮助我会说,要么在会话中存储值,要么在ASP:HiddenField中填充值,然后在Page_Load方法中将值放回文本框中。在页面内加载使用IfPage.IsPostback。
 using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;
    using System.Web.Security;
    using System.Text.RegularExpressions;

    public partial class Apartados_Administrar_Eventos_AltaEvento : System.Web.UI.Page
    {
        protected int IdEvento = 0;
        protected string _fechasEvento = "";
        protected string _fechaNuevaEvento = "";

    private void CargaFechasEvento( int eventoId)
        {
            using (SqlConnection Conn = conexionAdmin.Conecta())
            {
                using (SqlCommand cmdSelFechas = new SqlCommand("SelEventoByID", Conn))
                {
                    cmdSelFechas.CommandType = CommandType.StoredProcedure;
                    cmdSelFechas.Parameters.Add("@IDEVENTO", SqlDbType.Int).Value = eventoId;
                    Conn.Open();
                    SqlDataReader drEventos = cmdSelFechas.ExecuteReader();

                    if (drEventos.Read())
                    {
                       _fechasEvento = drEventos["Fecha_Evento"] == DBNull.Value ? "" : (string)drEventos["Fecha_Evento"];
                    }
                    drEventos.Close();
                    Conn.Close();
                    Conn.Dispose();
                }
            }
        }

        private void UpdStatusEvento(int IDNoticia, int Status, string idUser = "")
        {
            Guid userId = new Guid();
            if (idUser != "") { userId = new Guid(idUser); } // Conversion de string to Guid(el formato del UserId del Membership)
            using (SqlConnection Conn = conexionAdmin.Conecta())
            {
                using (SqlCommand CmdUpdStatusNoticia = new SqlCommand("UpStatusEvento", Conn))
                {
                    CmdUpdStatusNoticia.CommandType = CommandType.StoredProcedure;
                    CmdUpdStatusNoticia.Parameters.Add("@IDNOTICIA", SqlDbType.Int).Value = IDNoticia;

                    CmdUpdStatusNoticia.Parameters.Add("@STATUS", SqlDbType.Int).Value = Status;

                    if (idUser != "")
                    {
                        userId = new Guid(idUser);
                        CmdUpdStatusNoticia.Parameters.Add("@USERID", SqlDbType.UniqueIdentifier).Value = userId;
                    }
                    Conn.Open();
                    CmdUpdStatusNoticia.ExecuteNonQuery();
                    Conn.Close();
                    Conn.Dispose();
                }
            }
        }

        protected void btnGuardar_Click(object sender, EventArgs e)
        { 

            //No shows me the ID of the textbox does not display asp.net control and I value the value entered at the texbox
            //Response.Write(txtTituloEvento.Text);
            //Response.End();
                if (txtTituloEvento.Text.Trim() == "")
                {
                    lblMensaje.Text = Alertas.alertaError("", "El t&iacute;tulo del evento es obligatorio");
                    return;
                }
                if (Descripcion.Text.Trim() == "")
                {
                    lblMensaje.Text = Alertas.alertaError("", "La descripci&oacute;n del evento es obligatoria");
                    return;
                }

              if (!Regex.IsMatch(txtTituloEvento.Text, Utilidades.validaTextoGeneral))
                {
                    lblMensaje.Text = Alertas.alertaError("", "La Título del evento no puede contener caracteres especiales.");
                    return;
                }

                string comando = "InsEvento";
                if (IdEvento != 0)
                {
                    comando = "UpdEvento";
                }
                using (SqlConnection Conn = conexionAdmin.Conecta())
                {
                    using (SqlCommand cmdInsEvento = new SqlCommand(comando, Conn))
                    {
                        cmdInsEvento.Connection = Conn;
                        string user = HttpContext.Current.User.Identity.Name; // Usuario logueado
                        MembershipUser u = Membership.GetUser(user);
                        string idUser = u.ProviderUserKey.ToString(); // Se obtiene el id del usuario pero en formato string
                        Guid userId = new Guid(idUser); // Se convierte a GUID el idUser

                        cmdInsEvento.CommandType = CommandType.StoredProcedure;
                        cmdInsEvento.Parameters.Add("@TITULO", SqlDbType.NVarChar, 100).Value = txtTituloEvento.Text.Trim();
                        cmdInsEvento.Parameters.Add("@CONTENIDO", SqlDbType.NVarChar).Value = Descripcion.Text.Trim();
                        cmdInsEvento.Parameters.Add("@PUBLICAR", SqlDbType.Bit).Value = chkPublicar.Checked;
                        if (chkPublicar.Checked == true)
                        {
                            cmdInsEvento.Parameters.Add("@USERID", SqlDbType.UniqueIdentifier).Value = userId;
                        }
                        SqlParameter prmIdEvento = new SqlParameter("@IDEVENTO", SqlDbType.Int);
                        if (IdEvento != 0)
                        {
                            // update
                            cmdInsEvento.Parameters.Add("@IDEVENTO", SqlDbType.Int).Value = IdEvento;
                        }
                        else
                        {
                            // insert parametro de salida

                            prmIdEvento.Direction = ParameterDirection.Output;
                            cmdInsEvento.Parameters.Add(prmIdEvento);
                        }
                        Conn.Open();
                        cmdInsEvento.ExecuteNonQuery();
                        Conn.Close();
                        if (IdEvento == 0)
                        {
                            IdEvento = Convert.ToInt32(prmIdEvento.Value);
                            Response.Redirect("AltaEvento.aspx?Key=" + IdEvento);
                        }
                        lblMensaje.Text = Alertas.alertaExito("", "El evento se actualiz&oacute; correctamente");
                    } /
                }

        } 

        protected void btnVolver_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx");
        }

    }