umbraco event generation
H开发者_StackOverflow社区ow can we add events to a button using umbraco? My requirement is I have a button "button1" which is in a usercontrol page "login.ascx".whenever I click the button I need to go to home.ascx
<div style="border: 1px red;margin:30px 0px 0px 0px;width:auto; height: auto;text-align:center;"
id="login" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtpass" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="login" />
<asp:Button ID="Button2" runat="server" Text="Register" onclick="Button2_Click"
style="height: 26px" />
<br />
<asp:Label ID="lblmsg" runat="server"></asp:Label>
</div>
Any ideas?
you can't redirect to a usercontrol ie can't go from login.ascx to home.ascx.
You can do one thing add the login usercontrol as macro in one content page in umbraco and add home.ascx as other macro in other content page.
Then you can redirect from one content page to other using Response.Redirect.
With .NET usercontrols in Umbraco, you write them in exactly the same way you would for any other ASP.NET webforms application/website. Your code-behind should look like this:
protected void Button1_Click(object sender, EventArgs e) {
Response.Redirect("~/home.aspx");
}
If you want to specify a particular content node to redirect to, then you can specify a property on your usercontrol, and then when you create your Umbraco macro in the Developer section, you will be able to include the usercontrol property as a macro property, and add a Content Picker type to it to make it user-friendly for an admin to specify which page to redirect to. Example:
partial class MyUserControl : UserControl {
public int NodeToRedirectTo { get; set; }
protected void Button1_Click(object sender, EventArgs e) {
Response.Redirect(umbraco.library.NiceUrl(NodeToRedirectTo));
}
}
Hope this helps.
Benjamin
精彩评论