how to avoid postbacks
-
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
-
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
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.
-
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
The best way to avoid postbacks is to not develop Web applications.
-
The best way to avoid postbacks is to not develop Web applications.
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
-
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
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