3
votes

On my aspx page there are entry form with 10 text boxes, 1 drop-down(auto postback = true) and two buttons.

dropdown SelectedIndexChanged fills two text box value.

button1 name: "add" & button2 name:"update" On page load "update" visible = false

when click on "edit" from gridview, "add" visible = false and "update" visible = true. because of default page load "update" visible = false when i change drop-down, "update" button invisible.

So is it possible to Postback only Specific tools(in my case textbox) ?

Currently i am try with below code behind dropdown (i know it's crazy)

if (addbtn.Visible == true) {Button2.Visible = false;}

else if (addbtn.Visible == false) { Button2.Visible = true;}


page load

    protected void Page_Load(object sender, EventArgs e)
    {

        TextBox15.Enabled = false;
        TextBox16.Enabled = false;
        Button2.Visible = false;
        if (!IsPostBack)
        {
            bind_dropdown();

        }

   }

GridView rowcommand

protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "editform")
        {
          addbtn.Visible = false;
          Button2.Visible = true;
        }

bind dropdown

private void bind_dropdown()
    {
       DropDownList1.DataTextField = "CITYNAME";
       DropDownList1.DataValueField = "AID";
       DropDownList1.DataBind();
      }

dropdown change event

protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
    {

        if (addbtn.Visible == true)
        {
            Button2.Visible = false;

        }
        else if (addbtn.Visible == false)
        {

            Button2.Visible = true;
        }
        if (DropDownList1.SelectedIndex == 0)
        {

            TextBox15.Text = "";
            TextBox16.Text = "";



        }
        else
        {
            try
            {
2
Button2.Visible = !addbtn.Visible - phuzi

2 Answers

1
votes

As you don't give your code I can only guess what you're trying to achieve.

The best way to deal with this kind of problem is probably using AJAX as MKH proposed.

If you don't want to deal with AJAX you can also do it this way :

<form id="form1" runat="server">
    <div>
        <asp:DropDownList runat="server" ID="ddown" OnSelectedIndexChanged="ddown_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>

        <asp:TextBox runat="server" ID="tb"></asp:TextBox>

        <asp:LinkButton runat="server" ID="btn" OnClick="btn_Click"></asp:LinkButton>
    </div>
</form>

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ddown.Items.Add(new ListItem("Default", "-1"));
            ddown.Items.Add(new ListItem("text 0", "0"));
            ddown.Items.Add(new ListItem("text 1", "1"));
            ddown.Items.Add(new ListItem("text 2", "2"));
        }
    }

    protected void btn_Click(object sender, EventArgs e)
    {

    }

    protected void ddown_SelectedIndexChanged(object sender, EventArgs e)
    {
        tb.Text = ddown.SelectedItem.Text;
        btn.Visible = false;
    }

This way, you put in the "If(!Page.IsPostBack)" only the code that must be init once.

Then with the you can manage the "Visible" part from SelectedIndexChanged.

THis answer is not complete as I didn't totally understand what you need but that can be a piece of answer if AJAX scares you ;)

0
votes

Ajax, or update panel will do the trick, if you want to solve this with pure code behind, passing correct parameter to determine the layout can be done with validate the parameters and toggle the visible attribute in the page load.