Object values in ASP are not updated

0

Hello, I am handling the following form in ASP :

<tr>
  <td width="20%">
    <dx:ASPxLabel runat="server" Text="Documento"></dx:ASPxLabel>
  </td>
  <td width="20%">
    <dx:ASPxComboBox runat="server" ID="cbTipoDocPop" AutoPostBack="False" ClientVisible="true" EnableClientSideAPI="True"></dx:ASPxComboBox>
  </td>
  <td>
    <dx:ASPxTextBox runat="server" ID="txtCedulaPop"></dx:ASPxTextBox>
  </td>
</tr>
<tr>
  <td colspan="3">
    <asp:Button ID="btnEnviar" runat="server" Text="Traer Registros" OnClick="btnEnviar_Click" />
  </td>
</tr>
<tr>

At the moment of obtaining values using the function OnClick="btnEnviar_Click" does not take the values, it takes them as the initials as if they had not been changed.

protected void btnEnviar_Click(object sender, EventArgs e)
{
    if (txtCedulaPop.Text != null && cbTipoDocPop.SelectedIndex >= 0)
    {
        CustomEntity custom = new CustomEntity();
        custom.StringPrincipal = txtCedulaPop.Text;
        custom.StringSecundario = cbTipoDocPop.SelectedItem.Value.ToString();
        Pacientes pacienteActual = PatientFacade.GetByIdPacienteDocumento(custom);
        if (pacienteActual == null)
        {

            Response.Write("<script>alert('No se encontro Paciente');</script>");

        }
        else {

        }
    }
    else
    {
        Response.Write("<script>alert('Los campos son obligatorios');</script>");

    }
}

Regardless of what you type, you always recognize the fields as empty or with the values you assign them initially Am I doing wrong ?, so I ask your help to identify the problem, thank you very much

    
asked by Daniel ORTIZ 03.01.2017 в 19:07
source

1 answer

2

I was testing with your example and I realized that the line:

txtCedulaPop.Text != null

It is always true , because the property .Text never has null , try to change that part of the code for the following:

txtCedulaPop.Text != ""

Greetings.

Example:

Create a solution with form :

This is the code of the form:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="DevExpress.Web.v16.2, Version=16.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td width="20%">
                        <dx:aspxlabel runat="server" text="Documento"></dx:aspxlabel>
                    </td>
                    <td width="20%">
                        <dx:aspxcombobox runat="server" id="cbTipoDocPop" autopostback="False" clientvisible="true" enableclientsideapi="True"></dx:aspxcombobox>
                    </td>
                    <td>
                       <dx:ASPxTextBox runat="server" ID="txtCedulaPop"></dx:ASPxTextBox>
   </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <asp:Button ID="btnEnviar" runat="server" Text="Traer Registros" OnClick="btnEnviar_Click" />
                </td>
            </tr>
        </table>
    </div>
</form>

Codebehind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnEnviar_Click(object sender, EventArgs e)
    {
        if (txtCedulaPop.Text != "" )
        {
            Response.Write("<script>alert('" + txtCedulaPop.Text + "');</script>");
            // CustomEntity custom = new CustomEntity();
            //custom.StringPrincipal = txtCedulaPop.Text;
            //custom.StringSecundario = cbTipoDocPop.SelectedItem.Value.ToString();
            //Pacientes pacienteActual = PatientFacade.GetByIdPacienteDocumento(custom);
            //if (pacienteActual == null)
            //{

            //    Response.Write("<script>alert('No se encontro Paciente');</script>");

            //}
            //else
            //{

            //}
        }
        else
        {
            Response.Write("<script>alert('Los campos son obligatorios');</script>");

        }
    }
}

The running application:

Lastly, I added the source code:

Sample source code

    
answered by 03.01.2017 в 20:41