如何将代码隐藏代码添加到 umbraco 模板?

发布于 2024-09-16 19:53:21 字数 161 浏览 3 评论 0原文

我正在开始使用 umbraco 4.5.2。
我已经启动并运行了我的网站,并且正在使用一些 ASP.NET 控件设计模板。我如何响应这些控件的事件?

例如,我在模板中添加了一个按钮。如何编辑代码隐藏文件以在单击按钮时执行某些操作?

谢谢你,

马丁·维博

I am getting started with umbraco 4.5.2.
I have my site up and running, and I am designing templates using some ASP.NET controls. How can I respond to events from these controls?

For example, I have added a Button to a template. How can I edit the code-behind file to perform some action whenever the button is clicked?

Thank you,

Martin Wiboe

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

水晶透心 2024-09-23 19:53:21

实际上,您可以创建功能齐全的 ASP.NET .ascx 控件,并将它们包装在宏中以显示在模板/页面内。

观看精彩视频了解如何操作这。

祝你好运!

马尔科

You can actually create fully functional ASP.NET .ascx Controls, and wrap them in a Macro to display inside your template/page.

Check out this excellent video on how to do this.

Good luck!

Marko

花伊自在美 2024-09-23 19:53:21

看看这个博客文章

引用:

使用 Visual Studio 时,最好为模板提供代码隐藏文件(至少,我们就是这样做的)。如果您在 Umbraco 中创建模板,它会创建一个没有代码隐藏的母版页...

然后,您必须手动添加代码隐藏,将其与标记链接并创建设计器文件。这很糟糕吧?

只需这样做:

  1. 在 VS 中创建一个嵌套母版页,并使用“master”母版页作为母版页文件夹中的母版页。哈哈,这句话里有很多“母版页”,呵呵。
    VS 通过代码隐藏为您创建一个母版页,太棒了!
  2. VS 打开这个新创建的母版页的标记,保持打开状态!
  3. 然后转到 Umbraco 后端并像平常一样创建一个模板。
  4. 为其指定与第 1 步中定义的名称相同的名称。
  5. 这应该使用已创建的母版页作为文件来创建 Umbraco 模板。
  6. 现在返回 Visual Studio。它应该通知您文件已更改,并为您提供重新加载文件的选项。重新加载,然后使用 CTRL+Z 撤消 Umbraco 所做的更改(否则隐藏代码将不会链接到标记)并保存。
  7. 你已经完成了!

Have a look at the bottom of this blog post.

Quote:

When using Visual Studio, it’s nice to have code-behind files for your templates (at least, that’s how we do stuff). If you create a template in Umbraco, it creates a masterpage without code-behind…

Then you would have to add a code-behind manually, link it with the mark-up and create designer file. That sucks right?

Just do this:

  1. Create a nested masterpage in VS and use your ‘master’-masterpage as masterpage in the masterpages folder. Lol, there’s a lot of ‘masterpage’ in that sentence hehe.
    VS creates a masterpage for you with code-behind, sweet!
  2. VS opens the mark-up of this newly created masterpage, keep it opened!
  3. Then go to your Umbraco back-end and create a template like you would normally do.
  4. Give it the same name as you defined in step 1.
  5. This should create an Umbraco template by using the already created masterpage as file.
  6. Now return to Visual Studio. It should notify you that the file has changed and gives you the option to reload the file. Reload and then use CTRL+Z to undo the changes made by Umbraco (else the code-behind won’t be linked to the mark-up) and save it.
  7. You’re done!
晨曦÷微暖 2024-09-23 19:53:21

还有一个实用程序可以为您创建代码文件 http://umbracocs.codeplex.com/

There is also this utility that will create the codefiles for you http://umbracocs.codeplex.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文