Does the value of a textbox pass from one webform to another? ASP .NET C #

1

I have a webform1 in which I have a textbox sem.Text. Here is the code to pass that

value to a second webform

private string semana_x;
    public string semana
    {
        get
        {
                return semana_x;                
        }
       set
        {
         semana_x = value;
         this.sem.Text = value;
        }
    }


    protectedvoid b_Click(object sender, EventArgs e)
    {
        Response.Redirect("webf2.aspx?semana=" + semana);
    }

webform 2

//aqui recibo el valor del webf1 y lo convierto a int

int valor;
int.TryParse(Request.QueryString["semana"], out valor);
//para compararlo con un campo de BD

SqlCommand cmd = new SqlCommand("SELECT * from tabla where semana="+valor+",con);
//y mostrar todo en un gridview

SqlDataAdapter da = newSqlDataAdapter(cmd);
            DataTable dt = newDataTable();
            da.Fill(dt);
           gridview1.Visible = true;
           gridview1.DataSource = dt;
           gridview1.DataBind();
         con.Close();
        }

The problem is that when I write the number in the texbox it does not show me anything in the table and my

link appears like this: localhost: 49236 / Project / webf2.aspx? week =

but if I add a number at the end

link asi: webf2.aspx? semana = 48 < - asi, and if you show me the data in the gridview

I hope you can help me

Thanks

Greetings

    
asked by sunflower 09.03.2018 в 19:50
source

2 answers

2

For all we talked about in the comments, the values entered in your webform, are not being passed to your class.

Your property should be something like this:

private string semana_x;
public string semana
{
    get
    {
        return semana_x;                
    }
   set
    {
        semana_x = value;
    }
}

Somewhere, you should load that value into that property. Just as an example, let's suppose that we do it in the click (something that does not make much sense, because if we do it there, send it directly)

protectedvoid b_Click(object sender, EventArgs e)
{
    semana = this.sem.Text;
    Response.Redirect("webf2.aspx?semana=" + semana);
}

Something is thinking wrong if you armed the property the way you had armed it. Review concepts about that.

    
answered by 09.03.2018 / 20:38
source
1

You can also send it in one session and retrieve it in the next destination.

protectedvoid b_Click(object sender, EventArgs e)
{
    Session["variable"] = semana;
    Response.Redirect("webf2.aspx);
}
var semana = Session["variable"];
    
answered by 02.08.2018 в 16:26