Results 1 to 7 of 7

Thread: Referencing web forms

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2013
    Posts
    40

    Referencing web forms

    Hi everyone,

    Since I can´t find any answer to this by googling, Im pretty sure it´s a stupid question. But, anyways...

    I´m hoping to make a web version of a vb.net winforms app of mine, trying to learn asp.net in the process. I like to keep as much of my functionality as possible organized in classes depending on what it does and I often need to reference a control on a form from a class, for example, in vb.net:
    Code:
    If frmSomeForm.txtSomeTextBox.Text <> "" Then
    DoSomething
    End If
    In a webform project I can do the same thing in codebehind, but is it possible to reference a webform from a class, ie SomeWebForm.SomeControl? Or is there any other way to accomplish the same thing?

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Referencing web forms

    Under web applications things work differently, in a windows application it is quite normal to have multiple windows open and often for these windows to communicate with each other. In a web application however you have a browser displaying a page (the rendered HTML) and any information entered is posted back to the server - the concept of multiple open web pages communicating with each other doesn't really work.

    If you could give a little more detail about what you are trying to do then we might be able to suggest a different approach.

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2013
    Posts
    40

    Re: Referencing web forms

    Thanks for your reply Damp.

    Well, now, Im doing something pretty trivial, just to try it out. But: my app loads data from an external data source onto a grid, passes grid properties (like selected column) and contents of several dropdown boxes + some global variable settings (filters applied by buttons) to different classes where calculations are made on the data in the grid, then the grid is updated with calculated values. From the classes I make references f ex to the grid such as: Do something to values of some grid column.

    I don't think that things kept in classes because of reusability, such as connection strings and the like, are referencing any controls, and basically my use of classes is to keep thing tidy, avoiding thousands of lines of code in one block. So basically:

    1. What is a good approach to organising code for web apps? Using regions or something like that?

    2. Not knowing anything about coding for web, are there any other problems I don't know yet that I will run into? (to the extent that you feel like giving a tip of course, not trying to replace google).

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Referencing web forms

    Hello,

    In a webform project I can do the same thing in codebehind, but is it possible to reference a webform from a class, ie SomeWebForm.SomeControl?
    Or is there any other way to accomplish the same thing?
    - For web projects, you can't reference those control values unless they're in a master page.
    The appropriate method is to pass values among pages using state management in ASP.NET.
    Pass values between ASP.NET Pages

    What is a good approach to organising code for web apps? Using regions or something like that?
    - For large applications, you may organize code using N-Tier Architecture or MVP pattern.

    Not knowing anything about coding for web, are there any other problems I don't know yet that I will run into?
    - If you organize the codes properly such as applying a design pattern/architecture, then you don't have any major problems in the architectural level. Most of the issues
    might occur in your logic, pages and client-side.

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2013
    Posts
    40

    Re: Referencing web forms

    Thanks for your advice kgc!

  6. #6
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Referencing web forms

    One thing you will need to keep in mind is the way the web works, to get things to happen on the server side involves the client posting information to the server and the server rendering a new version of the page, if the user is making lots of changes to the grid this could either result in a lot of post-backs or the user not seeing any updates in the UI until they do something that causes a postback to occur.

    As Kgc has said, you will potentially need to track information on the server side to remember what the user has previously done if you want the UI to reflect these changes as well.

    A lot of modern apps will attempt to reduce the amount of HTML generated on the server side and rely on client side javascript to render updates in the browser, the scripts will often use AJAX to communicate with the server to submit or request data that is used to update the UI. This is quiet a major change in approach though if you are used to a windows environment and can involve learning a lot of technologies and architectural approaches before you can really do much.

    If your users are used to a dynamic UI and still want that then unfortunately the Javascript route is probably the best approach in the long term.

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2013
    Posts
    40

    Re: Referencing web forms

    Great points! Since I have no deadline for my transformation project, I suppose I may just as well do it right from the beginning. Guess I have a lot of work to do. Thanks for input!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width