Developer forum

Forum » Development » template extender running twice

template extender running twice


Reply

I have a little problem with the order template extender.

I have added two template tags to step 3 that takes a DataReader and fills the SetTags.

The problem is that there is double of every line.

It looks like it is runing it twice.

What can i do to prevent this from happening?

 


Replies

 
Reply

Hi Paul,

 

Since you say order, I'm glad, because that means that the software is working as intended. The OrderTemplateExtender runs twice, BeforeRender and AfterRender. You can use the second parameter in ExtendTemplate, which is  a Dynamicweb.eCommerce.Frontend.TemplateExtenderRenderingState type, to decide when to append your new tags:

 

if (RenderingState == Dynamicweb.eCommerce.Frontend.TemplateExtenderRenderingState.After)

 

or

 

if (RenderingState == Dynamicweb.eCommerce.Frontend.TemplateExtenderRenderingState.After)

 

But the issue of doubled rendering only applies to loops. Is that the case here also?

 

/Lars

 
Reply
Sorensen wrote:

Hi Paul,

 

Since you say order, I'm glad, because that means that the software is working as intended. The OrderTemplateExtender runs twice, BeforeRender and AfterRender. You can use the second parameter in ExtendTemplate, which is  a Dynamicweb.eCommerce.Frontend.TemplateExtenderRenderingState type, to decide when to append your new tags:

 

if (RenderingState == Dynamicweb.eCommerce.Frontend.TemplateExtenderRenderingState.After)

 

or

 

if (RenderingState == Dynamicweb.eCommerce.Frontend.TemplateExtenderRenderingState.After)

 

But the issue of doubled rendering only applies to loops. Is that the case here also?

 

/Lars


 

it's a loop so it worked

 

Thanks

 

/Paul

 

 

 
Reply

No problem:)

 
Reply

Got almost the same problem in step 6.

In step 6 I'm saving some of the order intormation in a file with a timestamp but some times it creates two files. I tried using the same metod as on step 3 but it doesn't work.

The problem is that it doesn't happen all the time.  

 

 
Reply

Just a thought: It's not that you're double clicking the "accept" link?

 
Reply
Sorensen wrote:

Just a thought: It's not that you're double clicking the "accept" link?


 

Tryed that and it doesn't mather how meny times you press the button.

It must be that it sometimes runs the method twice.

But why?

 
Reply

What object type are you using to save the data? A Notification Subscriber? Could you post your code here?

 
Reply

 

Sorensen wrote:

What object type are you using to save the data? A Notification Subscriber? Could you post your code here?

Im using a OrderTemplateExtender

 

...if (this.Order.StepNum == 6 && this.User.UserName != "")

 

}

 

 

 

...

 

System.Web.UI.Page p = new System.Web.UI.Page();
if (RenderingState == Dynamicweb.eCommerce.Frontend.TemplateExtenderRenderingState.Before)
{
                      
  string _timeStamp = DateTime.Now.ToString();
 _timeStamp = _timeStamp.Replace(" ", "");
 _timeStamp = _timeStamp.Replace("-", "");
 _timeStamp = _timeStamp.Replace(":", "");
 string _filename = Order.ID + _timeStamp + ".csv";
 FileInfo f = new FileInfo(p.Server.MapPath("/Files//Filer/Integration/eCommerce/Order/" + _filename));
 StreamWriter Tex = f.CreateText();
 Tex.WriteLine(_salesOrder.ToString());
 Tex.Write(Tex.NewLine);
 Tex.Close();
}

 

 
Reply

Hm... If it runs twice, you must get almost, if not pricecely, exact timestamps? What's the time difference?

 

Btw. what build are you running? We've had reportings about assemblies being loaded twice, but we fixed that a while ago.

 
Reply
Sorensen wrote:

Hm... If it runs twice, you must get almost, if not pricecely, exact timestamps? What's the time difference?

 

Btw. what build are you running? We've had reportings about assemblies being loaded twice, but we fixed that a while ago.


 

yes the timestamps are just a second appart.

 

it should be the latest build before the one comming this week

 
Reply

One second, that's a lot IMHO.

 

Have you tried Dynamicweb.Base.w() some text in the extender code? If it prints out twice also, it means that the extender is being run twice. If not, it seems as it's being initiated by two requests.

 
Reply
Sorensen wrote:

One second, that's a lot IMHO.

 

Have you tried Dynamicweb.Base.w() some text in the extender code? If it prints out twice also, it means that the extender is being run twice. If not, it seems as it's being initiated by two requests.


it prints it tree times every time

 
Reply

Could I ask you to download the latest Application.zip and use the assemblies from this archive in your custom solution?

 

You must be logged in to post in the forum