Home Adding ASP.NET Server Side Controls Dynamically Like as Javascript
Reply: 1

Adding ASP.NET Server Side Controls Dynamically Like as Javascript

Peter
1#
Peter Published in 2018-02-14 09:55:54Z

I have a simple aspx page.

In this page I want to add dynamically dropdownlist-textbox pairs that represent key-value pairs. But I dont know how much it is when page loading. So I must add these controls to page dynamically(in runtime)

If I add these controls in codebehind 2 problems arise :

  • Page is reloaded in every appending because of autopostback. It couses blink.
  • Whenever page reloads, previous appending disappear.

If I add these controls in client-side(javascript) :

  • Controls cannot be reachable in codebehind(because no runat=server) so validation steps open to user(I think validation steps must operate in codebehind othervise this is an integrity problem).

What would be true approach about this problem ? Could give example ?

PSK
2#
PSK Reply to 2018-02-14 10:18:26Z

If you want to avoid the blink(page reload) you have to go for adding the control dynamically into your form using JavaScript.

Controls cannot be reachable in codebehind(because no runat=server)

This statement is not correct, you can always access your form control at server side using Request.Form collection. Check here for more details. You will be required to iterate over the contents of this collection to get the values.

I think validation steps must operate in codebehind othervise this is an integrity problem

Validation you need to do by yourself before performing any operation. You might required to write some custom validation logic.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305405 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO