Web Connection
WW Web controls inside templates
Gravatar is a globally recognized avatar based on your email address. WW Web controls inside templates
  Kathy
  All
  Jan 9, 2019 @ 05:00pm

Hello,
Sorry for this basic question but could you please guide me how I can have WestWindWebControls inside my template content page (in webconnection 7.0)?
I'm using a template layout for my template content page (to have custom header and footer) and I need some wwWebConnectControls inside my template content page.
I've tried some approaches but I was not successful!
Thank you so much,
Kathy

Gravatar is a globally recognized avatar based on your email address. re: WW Web controls inside templates
  Rick Strahl
  Kathy
  Jan 9, 2019 @ 06:52pm

You can't use Web Controls inside of templates and scripts. Those are two separate stacks that don't really work together.

There is Response.ExpandPage() which sort of lets you embed a page, and you can in some cases also instantiate custom Web Controls and call their Render method to render them, but really this should be avoided. Pick one way to do things (Pages or Script/Templates) and stick to that - otherwise it gets too confusing.

Web Control Pages are end of life and won't get any new features, since there was hardly any adoption at the time. Scripts/Templates can do most of the things that Web Controls do now , with the improvements that started in Web Connection 6.0 and later. In fact with Layout Pages and Partials plus Request.FormOrValue() you get most of the benefits of Web Control pages in a simpler package now.

Hope this helps,

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: WW Web controls inside templates
  Kathy
  Rick Strahl
  Jan 10, 2019 @ 05:51am

Thank you so much.
I was trying to pull in my old pages into templates but now I try to use scripts/templates.
So I'm afraid I have to go through details but it's because I have not been able to get them to work.

I need to know how I can call a Foxpro function for a button click from my template page and how to get the values from the page into the function.
Let's say I have to get CKEditor.text and handle it by my Foxpro function through a submit button click.
I used to handle them in the .prg code behind while I was using wwWebButton and I had access to the this.ckEditor.text from the .prg code behind.
Would you please guide me how I can do it on my templates now?
<input type="button" ID="btnSubmit" runat="server" Text="Submit" width="180" onclick="btnSubmit_Click" />

Thank you again,
Kathy

Gravatar is a globally recognized avatar based on your email address. re: WW Web controls inside templates
  Rick Strahl
  Kathy
  Jan 10, 2019 @ 08:58pm

With templates and scripts you need to submit the form and then check for specific button in the process method:

FUNCTION CustomerForm

lcId = Request.QueryString("Id")

poCustomer = CREATEOBJECT("CustomerBusiness")

IF !poCustomer.Load(lcId)
   poCustomer.New()
ENDIF

*** if it's postback the button has been clicked
IF Request.IsPostBack()
   poError.Errors = Request.UnbindFormVars(poCustomer.oData)

   IF !poCustomer.Validate()
       poError.Errors.AddErrors( poCustomer.oValidationErrors )
   ENDIF
   
   IF poError.Errors.Count < 1 
       IF !poCustomer.Save() 
	      poError.Message = poCustomer.cErrorMsg      
       ENDIF  
   ENDIF

   IF (poError.Errors.Count > 0)
   	  poError.Message = poError.Errors.ToHtml()
   	   poError.Header = "Please fix the following form entry errors"
   ELSE
       poError.Message = "Entry saved."
       poError.Icon = "info"
       Response.AppendHeader("Refresh","2;url=.\")
   ENDIF               
ENDIF

Response.ExpandScript()
ENDFUNC

The form above is both an display and input form so it handles the initial display and saving the data along with error info.

If you have multiple buttons you need to handle you can check for specific button clicks:

DO CASE 
  CASE Request.IsFormVar("btnSave")     
      * Perform save code

      *** if it's a lot of code externalize it from the current method
      * RETURN THIS.SaveCustomer()
  CASE Request.IsFormVar("btnMakeInactive")
     * perform change inactive logic
ENDCASE

I recommend you go through the Business object walk through:

which has a lot more info on how to do this.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: WW Web controls inside templates
  Kathy
  Rick Strahl
  Jan 11, 2019 @ 01:09pm

Thank you so much for the details and the helpful link.
It's up and running beautifully.
I just need to confirm this again. So all functions and page handlers will be in MyProcess.prg for templates and scripts, is that right?
Thanks,
Kathy

Gravatar is a globally recognized avatar based on your email address. re: WW Web controls inside templates
  Rick Strahl
  Kathy
  Jan 11, 2019 @ 05:31pm

Yes, but you can break out most of the business logic into business objects - there should not be a lot of code in those process methods.

If you are worried about the size of the process class you can also create helpers that do some of the more complex processing to keep things tidier:

FUNCTION ProcessMethod()
loCustomerHelper = CREATEOBJECT("CustomerHelper")
RETURN loCustomerHelper.ProcessMethod()
ENDFUNC

Then in the ProcessHelper you can basically implement the logic you normally implement in the process class. You still have access to all the same intrinsic objects Process, Request, Response, Session, Server etc. This allows you to keep the actual process class really small and you can have multiple helpers to isolate related tasks together. This all makes sense only if you have process classes with a lot of functionality.

Otherwise you can also create multiple process classes for each sub-section of your application with separate script maps for each.

Gravatar is a globally recognized avatar based on your email address. re: WW Web controls inside templates
  Kathy
  Rick Strahl
  Jan 14, 2019 @ 02:28pm

Your advice is so helpful and precious as always.
Thank you so much.
Kathy

© 1996-2019