Developer forum

Forum » Development » DynamicWeb Controls Button no click event

DynamicWeb Controls Button no click event

Casper Andersen
Reply

I am atm developing a custom module, i am using one examples called DwExample to get me started, everything works so far, but now i want to add a button my edit.aspx page, and as far as i understand i should do it like this

<dw:Button runat="server" id="UpdateNumber" EnableServerClick="true" onclick="UpdateNumber_Click"></dw:Button>

And while we are at it, is there a list somewhere that shows all the available <dw tags and what parameters they accept ?

then in my .cs file i have in my Page_Load this code UpdateNumber.OnClick += new EventHandler<EventArgs>(UpdateNumber_Click);

Which is tied to this code

protected void UpdateNumber_Click(object sender, EventArgs e)
{
     Response.Redirect("http://www.google.com");
}

but this gives me a Uncaught SyntaxError: Unterminated template literal

Anyone know what is happening here ?


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Casper

It sounds like a missing " in one of your attributes somewhere in that .aspx file - i need the entire file to see more.

You should have a look at the custom modules articles at thise page: http://devierkoeden.com/articles.aspx

You can find all controls available by dw: prefix by installing Dynamicweb.Controls in your Visual Studio toolbox. You can probably also just write <dw: and get intellisense to tell you what is available (if you have a reference to Dynamicweb.Conrols in your VS solution)¨

BR Nicolai

 
Casper Andersen
Reply

This is my DwExample_Edit.aspx file

<%@ Page Language="C#" AutoEventWireup="true" Codebehind="DwExample_Edit.aspx.cs" Inherits="CustomModules.CustomModules.DwExample.DwExample_Edit" %>
<%@ Register Assembly="Dynamicweb.Controls" Namespace="Dynamicweb.Controls" TagPrefix="dw" %>
<dw:ModuleHeader ID="ModuleHeader1" runat="server" ModuleSystemName="DwExample" />
<dw:ModuleSettings ID="ModuleSettings1" runat="server" ModuleSystemName="DwExample" Value="myText, myTemplate" />
    
<dw:GroupBox ID="GroupBox1" runat="server" Title="Settings">
    <table>
        <tr>
            <td width="170">My text
            </td>
            <td><input type="text" runat="server" id="myText" name="myText" class="std" />
            </td>
        </tr>
        <tr>
            <td width="170">
                Template
            </td>
            <td>
                <dw:FileManager ID="myTemplate" runat="server" Folder="/Templates/DwExample" />
            </td>
        </tr>
        <tr>
            <td width="170">
                My Date
            </td>
            <td>
                <label id="DateLabel" runat="server"></label>
            </td>
        </tr>
        <
        <tr>
            <td width="170">
                My Number
            </td>
            <td>
                <dw:Button runat="server" id="UpdateNumber" EnableServerClick="true" onclick="UpdateNumber_Click"></dw:Button>
            </td>
        </tr>
    </table>
</dw:GroupBox>

 
Casper Andersen
Reply

And just for good measure this is my .cs file

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Dynamicweb.Controls;

namespace CustomModules.CustomModules.DwExample
{
    public partial class DwExample_Edit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            

            Dynamicweb.Properties p = Dynamicweb.Properties.LoadProperties();
            Dynamicweb.Content.Items.Item myItemPage = Dynamicweb.Content.Items.Item.GetItemById("Paragraph","81");
            var te = myItemPage["Custom_Number"];
            te = 9;
            myItemPage.Save();

            UpdateNumber.OnClick += new EventHandler<EventArgs>(UpdateNumber_Click);

            p.SetDefaultValue("myText", "Hello world!");
            p.SetDefaultValue("myTemplate", "Test.html");
            p.SetDefaultValue("DateLabel", "1-1-1991");

            myText.Value = p.Values["myText"].ToString();
            myTemplate.File = p.Values["myTemplate"].ToString();
            DateLabel.InnerText = p.Values["DateLabel"].ToString();
        }
        protected void UpdateNumber_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://www.google.com");
        }
    }
}

 
Nicolai Høeg Pedersen
Reply

Hi Casper

Your markup seems broken - you have an opening < sitting in the middle of it all...

 
Casper Andersen
Reply

You are correct, although i did before this, have one without the < mistake, and i just recreated that, and now i get this error Uncaught SyntaxError: Unterminated template literal dont know if that makes any difference, also i am thinking, shouldent this line 

UpdateNumber.OnClick += new EventHandler<EventArgs>(UpdateNumber_Click);

be

UpdateNumber.Click += new EventHandler<EventArgs>(UpdateNumber_Click);

? I know that if i use a normal asp:Button then i get the opportunity to use .Click in my cs file but with the dw:Button it only shows me OnClick and if i try to use .Click it tells me its not allowed. Any thought on this and thanks a lot with your help so far!

 
Nicolai Høeg Pedersen
Reply

Hi Casper

This control only has a OnClick and that is a serverside js onclick event - and it inherits a normal webcontrol (and not a asp button).

So, I do not think you can do this - so you should probably use the asp button instead if you need serverside click event.

NP

 
Casper Andersen
Reply

I thought about this to start with, but i have not been able to get it to work,

even if i just pull a button out form my toolbox in VS that looks like this <asp:Button runat="server" Text="Button"></asp:Button>

but then i get this

GET http://custommodules.local.dynamicweb.dk:8082/Admin/Content/ParagraphEditMo…hModule_onSettingsChanged&OnRemoveCallback=ParagraphModule_onModuleRemoved 500 (Internal Server Error)

Which makes no sense to me at all, does it have anything to do with me using

<%@ Register Assembly="Dynamicweb.Controls" Namespace="Dynamicweb.Controls" TagPrefix="dw" %>

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Casper,

For that last code change, what's the error you are getting?

Imar

 
Casper Andersen
Reply

As i said, i just added <asp:Button runat="server" Text="Button"></asp:Button> and got 

GET http://custommodules.local.dynamicweb.dk:8082/Admin/Content/ParagraphEditMo…hModule_onSettingsChanged&OnRemoveCallback=ParagraphModule_onModuleRemoved 500 (Internal Server Error)

 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

But can't you see what the error is? Is something hiding the actual error? Would be useful to see what's going on.....

 
Casper Andersen
Reply

I'm not sure what i can do here, i am using this code in my custom module, and the module just wont work / load if i get any errors, the error i am giving u, is the error i am getting from the browser console, hope this clears up some stuff

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Try finding out what the real error is; mybe the Windows Event Viewer tells you more, or maybe you can show more errors by disabling customErrors in web.config.

Finally, I think this is wrong:

UpdateNumber.Click += new EventHandler<EventArgs>(UpdateNumber_Click);

Try changing it to:

UpdateNumber.Click += new EventHandler(UpdateNumber_Click);

or better yet:

UpdateNumber.Click += UpdateNumber_Click;

Hope this helps,

Imar

 
Casper Andersen
Reply

The biggest problem atm, is that i can not add <asp:Button runat="server" Text="Button"></asp:Button> to my .aspx file, as soon as i add some the asp button control, my module crashes, is it even possible to use asp controls ?

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Casper

If it is the SystemName_Edit.aspx file used for module settings on the paragraph you cannot, any other files you can use whatever.

The reason is, that ParagraphEdit loads the file dynamically.

BR Nicolai

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Ah, yes, that would explain it. For more background and a potential work around, take a look at my blog post: http://devierkoeden.com/articles/custom-modules-part-2-a-using-user-controls-for-the-edit-page.aspx

Imar

 
Casper Andersen
Reply

Ahh that explains so much! A big thanks to both of you!

 

You must be logged in to post in the forum