Click here to Skip to main content
16,005,169 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: How can I create or/and navigate to an event handler for a server control in vs2005? Pin
minhpc_bk15-Aug-06 22:17
minhpc_bk15-Aug-06 22:17 
GeneralRe: How can I create or/and navigate to an event handler for a server control in vs2005? Pin
Carolina15-Aug-06 22:31
Carolina15-Aug-06 22:31 
GeneralRe: How can I create or/and navigate to an event handler for a server control in vs2005? Pin
minhpc_bk15-Aug-06 22:40
minhpc_bk15-Aug-06 22:40 
GeneralRe: How can I create or/and navigate to an event handler for a server control in vs2005? Pin
Carolina15-Aug-06 23:17
Carolina15-Aug-06 23:17 
GeneralRe: How can I create or/and navigate to an event handler for a server control in vs2005? Pin
minhpc_bk16-Aug-06 0:54
minhpc_bk16-Aug-06 0:54 
GeneralRe: How can I create or/and navigate to an event handler for a server control in vs2005? Pin
Carolina16-Aug-06 1:26
Carolina16-Aug-06 1:26 
GeneralRe: How can I create or/and navigate to an event handler for a server control in vs2005? Pin
minhpc_bk16-Aug-06 15:53
minhpc_bk16-Aug-06 15:53 
GeneralRe: How can I create or/and navigate to an event handler for a server control in vs2005? Pin
Carolina16-Aug-06 20:16
Carolina16-Aug-06 20:16 
Sure, no problem.
I've cleared out some of the code that references my business logic class, since you dont have access to it. This includes a public property for assigning an instance of my BL-class to the control, and this property shows up in the properties window in design mode when this control is included in a web page.

This is the source for one of my ascx pages:


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EducationEdit.ascx.cs" Inherits="cv_EducationEdit" %>
<table width="600">
<tr>
<td align="right">
<asp:LinkButton ID="btnAddEducation" runat="server" Text="[Lägg till utbildning och kurser]" OnClick="btnAddEducation_Click"/>
</td>
</tr>
</table>
<asp:Panel ID="pnlEditEducation" runat="server" Visible="false">
<table width="600">
<tr>
<td>Typ</td><td><asp:DropDownList ID="ddlType" runat="server"/></td>
</tr>
<tr>
<td>Utbildning</td><td><asp:DropDownList ID="ddlName" runat="server"/></td><td><asp:TextBox ID="txtName" runat="server"/><asp:Button ID="btnNewName" runat="server" Text="Ny" OnClick="btnNewName_Click" CssClass="stdButton"/></td>
</tr>
<tr>
<td>Institut</td><td><asp:DropDownList ID="ddlEducator" runat="server"/></td><td><asp:TextBox ID="txtEducator" runat="server"/><asp:Button ID="btnNewPlace" runat="server" Text="Ny" OnClick="btnNewEducator_Click" /></td>
</tr>
<tr>
<td>Datum</td><td><asp:DropDownList ID="ddlStartYear" runat="server"/>-<asp:DropDownList ID="ddlStartMonth" runat="server"/> - <asp:DropDownList ID="ddlEndYear" runat="server"/>-<asp:DropDownList ID="ddlEndMonth" runat="server"/></td>
</tr>
<tr>
<td>Visa vid export</td><td>
<asp:CheckBox ID="ShowInFile" runat="server" /></td>
</tr>
<tr>
<td><asp:Button ID="btnSave" runat="server" Text="Spara" OnClick="btnSave_Click" CssClass="stdButton"/><asp:Button ID="btnCancel" runat="server" Text="Avbryt" OnClick="btnCancel_Click" CssClass="stdButton"/></td>
</tr>
</table>
</asp:Panel>




And this is the corresponding code-behind (.cs):



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;

public partial class cv_EducationEdit : System.Web.UI.UserControl {
public delegate void UpdateEventHandler();
public event UpdateEventHandler Update;

private const string PAGESESSION_EDUCATION = "pEducation";



/// <summary>
/// Fills the drop downs
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
pFillEditValues();
}
}
/// <summary>
/// Fires an update event to inform the parent control that the current item has been saved and updated.
/// Used for informing the parent control to update all lists with Technical Skills
/// </summary>
protected virtual void OnUpdate() {
if (Update != null) {
// Invokes the delegates.
Update();
}
}
/// <summary>
/// Fills the drop downs and text boxes with possible values
/// </summary>
private void pFillEditValues() {
//Code to fill drop down combos
}
/// <summary>
/// Adds a new name of educations to select from
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNewName_Click(object sender, EventArgs e) {
ListItem li = new ListItem(txtName.Text, txtName.Text);
ddlName.Items.Add(li);
ddlName.SelectedIndex = -1;
li.Selected = true;
txtName.Text = "";
}
/// <summary>
/// Adds a new educator of educations to select from
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNewEducator_Click(object sender, EventArgs e) {
ListItem li = new ListItem(txtEducator.Text, txtEducator.Text);
ddlEducator.Items.Add(li);
ddlEducator.SelectedIndex = -1;
li.Selected = true;
txtEducator.Text = "";
}
/// <summary>
/// Hides the new button and opens the control in edit mode with a new blank item
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAddEducation_Click(object sender, EventArgs e) {
pnlEditEducation.Visible = true;
btnAddEducation.Visible = false;
}
/// <summary>
/// Saves the current item, hides the edit panel, shows the add button and fires an Update event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e) {
//Create or update my custom object
txtName.Text = "";
txtEducator.Text = "";

//Trigger event
OnUpdate();

pnlEditEducation.Visible = false;
btnAddEducation.Visible = true;
}
/// <summary>
/// Hides the edit panel and displays the add button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCancel_Click(object sender, EventArgs e) {
pnlEditEducation.Visible = false;
btnAddEducation.Visible = true;
}
}



And this is the code I use for including the control in a web page(aspx):

<div class="cvParagraph">
<uc4:EducationEdit ID="EducationEdit1" runat="server" OnUpdate="EducationEdit_Update" />
</div>


Thank you for taking your time with me!

Carolina Berglund
Consultant, systemdeveloper and architect.
GeneralRe: How can I create or/and navigate to an event handler for a server control in vs2005? Pin
minhpc_bk16-Aug-06 21:25
minhpc_bk16-Aug-06 21:25 
GeneralRe: How can I create or/and navigate to an event handler for a server control in vs2005? Pin
Carolina16-Aug-06 21:48
Carolina16-Aug-06 21:48 
Questionrunning java script on page loading Pin
248912815-Aug-06 19:03
248912815-Aug-06 19:03 
AnswerRe: running java script on page loading Pin
_AK_15-Aug-06 19:10
_AK_15-Aug-06 19:10 
GeneralRe: running java script on page loading Pin
248912815-Aug-06 19:14
248912815-Aug-06 19:14 
GeneralRe: running java script on page loading Pin
psamy15-Aug-06 19:26
psamy15-Aug-06 19:26 
GeneralRe: running java script on page loading Pin
_AK_15-Aug-06 19:32
_AK_15-Aug-06 19:32 
GeneralRe: running java script on page loading Pin
248912815-Aug-06 19:38
248912815-Aug-06 19:38 
GeneralRe: running java script on page loading Pin
_AK_15-Aug-06 19:56
_AK_15-Aug-06 19:56 
GeneralRe: running java script on page loading Pin
248912815-Aug-06 20:17
248912815-Aug-06 20:17 
GeneralRe: running java script on page loading Pin
_AK_15-Aug-06 20:26
_AK_15-Aug-06 20:26 
AnswerRe: running java script on page loading Pin
Guffa15-Aug-06 21:13
Guffa15-Aug-06 21:13 
QuestionASP.Net 2 authentication WITHOUT the new stuff? [modified] Pin
cdengler15-Aug-06 18:13
cdengler15-Aug-06 18:13 
AnswerRe: ASP.Net 2 authentication WITHOUT the new stuff? Pin
minhpc_bk15-Aug-06 22:15
minhpc_bk15-Aug-06 22:15 
GeneralRe: ASP.Net 2 authentication WITHOUT the new stuff? Pin
cdengler16-Aug-06 5:13
cdengler16-Aug-06 5:13 
GeneralRe: ASP.Net 2 authentication WITHOUT the new stuff? Pin
cdengler21-Aug-06 11:56
cdengler21-Aug-06 11:56 
QuestionHow to register a javascript function [modified] Pin
Mairy15-Aug-06 17:53
Mairy15-Aug-06 17:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.