is it possible to Postback only Specific tools?











up vote
3
down vote

favorite












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
{









share|improve this question
























  • Button2.Visible = !addbtn.Visible
    – phuzi
    5 hours ago















up vote
3
down vote

favorite












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
{









share|improve this question
























  • Button2.Visible = !addbtn.Visible
    – phuzi
    5 hours ago













up vote
3
down vote

favorite









up vote
3
down vote

favorite











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
{









share|improve this question















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
{






c# asp.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago

























asked 9 hours ago









ronak6985

163




163












  • Button2.Visible = !addbtn.Visible
    – phuzi
    5 hours ago


















  • Button2.Visible = !addbtn.Visible
    – phuzi
    5 hours ago
















Button2.Visible = !addbtn.Visible
– phuzi
5 hours ago




Button2.Visible = !addbtn.Visible
– phuzi
5 hours ago












3 Answers
3






active

oldest

votes

















up vote
1
down vote













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 ;)






share|improve this answer





















  • thanks. i am already managing using btn.Visible = false; and btn.Visible = true;
    – ronak6985
    4 hours ago












  • I don't think the problem is on your Visible/Hide management but more on where you use them and how you deal with Postback. Could you share your code so we can help ?
    – Grégory L
    4 hours ago










  • i have updated my question with code.
    – ronak6985
    3 hours ago










  • If I understand well, your problem is that the page load put the button update back to invisible ? In this case why don't you put the "visible = false" in the If(!Page.IsPostBack) ?
    – Grégory L
    1 hour ago










  • And actually I would suggest to put also the textbox disable in the condition too.
    – Grégory L
    1 hour ago


















up vote
0
down vote













Use AJAX , please take a look at Partial PostBack using UpdatePanel and ScriptManager Control Overview posts to implement it.






share|improve this answer




























    up vote
    0
    down vote













    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.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53368776%2fis-it-possible-to-postback-only-specific-tools%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote













      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 ;)






      share|improve this answer





















      • thanks. i am already managing using btn.Visible = false; and btn.Visible = true;
        – ronak6985
        4 hours ago












      • I don't think the problem is on your Visible/Hide management but more on where you use them and how you deal with Postback. Could you share your code so we can help ?
        – Grégory L
        4 hours ago










      • i have updated my question with code.
        – ronak6985
        3 hours ago










      • If I understand well, your problem is that the page load put the button update back to invisible ? In this case why don't you put the "visible = false" in the If(!Page.IsPostBack) ?
        – Grégory L
        1 hour ago










      • And actually I would suggest to put also the textbox disable in the condition too.
        – Grégory L
        1 hour ago















      up vote
      1
      down vote













      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 ;)






      share|improve this answer





















      • thanks. i am already managing using btn.Visible = false; and btn.Visible = true;
        – ronak6985
        4 hours ago












      • I don't think the problem is on your Visible/Hide management but more on where you use them and how you deal with Postback. Could you share your code so we can help ?
        – Grégory L
        4 hours ago










      • i have updated my question with code.
        – ronak6985
        3 hours ago










      • If I understand well, your problem is that the page load put the button update back to invisible ? In this case why don't you put the "visible = false" in the If(!Page.IsPostBack) ?
        – Grégory L
        1 hour ago










      • And actually I would suggest to put also the textbox disable in the condition too.
        – Grégory L
        1 hour ago













      up vote
      1
      down vote










      up vote
      1
      down vote









      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 ;)






      share|improve this answer












      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 ;)







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered 5 hours ago









      Grégory L

      106111




      106111












      • thanks. i am already managing using btn.Visible = false; and btn.Visible = true;
        – ronak6985
        4 hours ago












      • I don't think the problem is on your Visible/Hide management but more on where you use them and how you deal with Postback. Could you share your code so we can help ?
        – Grégory L
        4 hours ago










      • i have updated my question with code.
        – ronak6985
        3 hours ago










      • If I understand well, your problem is that the page load put the button update back to invisible ? In this case why don't you put the "visible = false" in the If(!Page.IsPostBack) ?
        – Grégory L
        1 hour ago










      • And actually I would suggest to put also the textbox disable in the condition too.
        – Grégory L
        1 hour ago


















      • thanks. i am already managing using btn.Visible = false; and btn.Visible = true;
        – ronak6985
        4 hours ago












      • I don't think the problem is on your Visible/Hide management but more on where you use them and how you deal with Postback. Could you share your code so we can help ?
        – Grégory L
        4 hours ago










      • i have updated my question with code.
        – ronak6985
        3 hours ago










      • If I understand well, your problem is that the page load put the button update back to invisible ? In this case why don't you put the "visible = false" in the If(!Page.IsPostBack) ?
        – Grégory L
        1 hour ago










      • And actually I would suggest to put also the textbox disable in the condition too.
        – Grégory L
        1 hour ago
















      thanks. i am already managing using btn.Visible = false; and btn.Visible = true;
      – ronak6985
      4 hours ago






      thanks. i am already managing using btn.Visible = false; and btn.Visible = true;
      – ronak6985
      4 hours ago














      I don't think the problem is on your Visible/Hide management but more on where you use them and how you deal with Postback. Could you share your code so we can help ?
      – Grégory L
      4 hours ago




      I don't think the problem is on your Visible/Hide management but more on where you use them and how you deal with Postback. Could you share your code so we can help ?
      – Grégory L
      4 hours ago












      i have updated my question with code.
      – ronak6985
      3 hours ago




      i have updated my question with code.
      – ronak6985
      3 hours ago












      If I understand well, your problem is that the page load put the button update back to invisible ? In this case why don't you put the "visible = false" in the If(!Page.IsPostBack) ?
      – Grégory L
      1 hour ago




      If I understand well, your problem is that the page load put the button update back to invisible ? In this case why don't you put the "visible = false" in the If(!Page.IsPostBack) ?
      – Grégory L
      1 hour ago












      And actually I would suggest to put also the textbox disable in the condition too.
      – Grégory L
      1 hour ago




      And actually I would suggest to put also the textbox disable in the condition too.
      – Grégory L
      1 hour ago












      up vote
      0
      down vote













      Use AJAX , please take a look at Partial PostBack using UpdatePanel and ScriptManager Control Overview posts to implement it.






      share|improve this answer

























        up vote
        0
        down vote













        Use AJAX , please take a look at Partial PostBack using UpdatePanel and ScriptManager Control Overview posts to implement it.






        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          Use AJAX , please take a look at Partial PostBack using UpdatePanel and ScriptManager Control Overview posts to implement it.






          share|improve this answer












          Use AJAX , please take a look at Partial PostBack using UpdatePanel and ScriptManager Control Overview posts to implement it.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 5 hours ago









          MKH

          538




          538






















              up vote
              0
              down vote













              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.






              share|improve this answer

























                up vote
                0
                down vote













                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.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 5 hours ago









                  Chris

                  456




                  456






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53368776%2fis-it-possible-to-postback-only-specific-tools%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Volksrepublik China

                      How to test boost logger output in unit testing?

                      Write to the output between two pipeline