Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to avoid postbacks

how to avoid postbacks

Scheduled Pinned Locked Moved C#
helpc++csssysadmintutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    ShaikhAffi
    wrote on last edited by
    #1

    Hi all i have implemented a small application in which a button is placed named addRow when user clicks tht button a row is added in a grid view,whever user clicks it row will be added to the existing gridview i have done this with the following code now the problem is when i refresh the page the row is added or when i click any server control the row is also added bt i dont want this i just want the row shud be added when the button name addRow is clicked only. any help will be greatly appreciated.thanks in advance Code: ( cpp ) 1. protected void Page_Load(object sender, EventArgs e) 2. { 3. if (!Page.IsPostBack) 4. Session["dt"] = null; 5. 6. } 7. protected override void OnPreInit(EventArgs e) 8. { 9. base.OnPreInit(e); 10. if (Request.Form["hf"] == "true") 11. addGVRow(); 12. hf.Value = string.Empty; 13. } 14. 15. 16. private void addGVRow() 17. { 18. DataTable dt = (DataTable)Session["dt"]; 19. int counter = 0; 20. if (dt == null) 21. { 22. dt = new DataTable(); 23. dt.Columns.Add("seq"); 24. } 25. else 26. counter = dt.Rows.Count; 27. DataRow dr = dt.NewRow(); 28. dr[0] = counter + 1; 29. dt.Rows.Add(dr); 30. gv.DataSource = dt; 31. gv.DataBind(); 32. Session["dt"] = dt; 33. } and on aspx page for the button

    L P 2 Replies Last reply
    0
    • S ShaikhAffi

      Hi all i have implemented a small application in which a button is placed named addRow when user clicks tht button a row is added in a grid view,whever user clicks it row will be added to the existing gridview i have done this with the following code now the problem is when i refresh the page the row is added or when i click any server control the row is also added bt i dont want this i just want the row shud be added when the button name addRow is clicked only. any help will be greatly appreciated.thanks in advance Code: ( cpp ) 1. protected void Page_Load(object sender, EventArgs e) 2. { 3. if (!Page.IsPostBack) 4. Session["dt"] = null; 5. 6. } 7. protected override void OnPreInit(EventArgs e) 8. { 9. base.OnPreInit(e); 10. if (Request.Form["hf"] == "true") 11. addGVRow(); 12. hf.Value = string.Empty; 13. } 14. 15. 16. private void addGVRow() 17. { 18. DataTable dt = (DataTable)Session["dt"]; 19. int counter = 0; 20. if (dt == null) 21. { 22. dt = new DataTable(); 23. dt.Columns.Add("seq"); 24. } 25. else 26. counter = dt.Rows.Count; 27. DataRow dr = dt.NewRow(); 28. dr[0] = counter + 1; 29. dt.Rows.Add(dr); 30. gv.DataSource = dt; 31. gv.DataBind(); 32. Session["dt"] = dt; 33. } and on aspx page for the button

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      It's considered rude. If you want to find out how post back in ASP.NET works try reading the freaking documentation! Sorry for the outburst everyone but it's like the 15th time today I have seen this type of lazy garbage and on top of it this jerk reposts his question.

      1 Reply Last reply
      0
      • S ShaikhAffi

        Hi all i have implemented a small application in which a button is placed named addRow when user clicks tht button a row is added in a grid view,whever user clicks it row will be added to the existing gridview i have done this with the following code now the problem is when i refresh the page the row is added or when i click any server control the row is also added bt i dont want this i just want the row shud be added when the button name addRow is clicked only. any help will be greatly appreciated.thanks in advance Code: ( cpp ) 1. protected void Page_Load(object sender, EventArgs e) 2. { 3. if (!Page.IsPostBack) 4. Session["dt"] = null; 5. 6. } 7. protected override void OnPreInit(EventArgs e) 8. { 9. base.OnPreInit(e); 10. if (Request.Form["hf"] == "true") 11. addGVRow(); 12. hf.Value = string.Empty; 13. } 14. 15. 16. private void addGVRow() 17. { 18. DataTable dt = (DataTable)Session["dt"]; 19. int counter = 0; 20. if (dt == null) 21. { 22. dt = new DataTable(); 23. dt.Columns.Add("seq"); 24. } 25. else 26. counter = dt.Rows.Count; 27. DataRow dr = dt.NewRow(); 28. dr[0] = counter + 1; 29. dt.Rows.Add(dr); 30. gv.DataSource = dt; 31. gv.DataBind(); 32. Session["dt"] = dt; 33. } and on aspx page for the button

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        The best way to avoid postbacks is to not develop Web applications.

        A 1 Reply Last reply
        0
        • P PIEBALDconsult

          The best way to avoid postbacks is to not develop Web applications.

          A Offline
          A Offline
          Anthony Mushrow
          wrote on last edited by
          #4

          Well, it is guaranteed to work :rolleyes:

          My current favourite word is: PIE! I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for. -The Undefeated

          S 1 Reply Last reply
          0
          • A Anthony Mushrow

            Well, it is guaranteed to work :rolleyes:

            My current favourite word is: PIE! I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for. -The Undefeated

            S Offline
            S Offline
            ShaikhAffi
            wrote on last edited by
            #5

            very funny well i did post the coding i just not want to execute the code on every post back any help will be highly appreciated

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups