PC Review


Reply
Thread Tools Rate Thread

Custom onclick event for composite control

 
 
AndrewF
Guest
Posts: n/a
 
      5th Aug 2005
Hi there.

I am royally stuck with this so any help would be greatly appreciated.

Basically I have a set of classes that create composite controls for
the user. One of these is an upload object so users can upload files to
the server as part of the CMS.

The composite control contains:

HtmlInputFile object to get the path name,
Somer literal controls holding some bumf HTML to tell the user what
they have uploaded etc.
a Button control called funnily enough "Upload".

Now if these items were just dumped onto a page at design time I
wouldn't have a problem as I could wire up the server onclick event
without any drama at all as I could whack it in the tag - this is all
built at runtime however and it doesn't appear to be that simple.

I have got a class thus:

// infControls.File.cs
//



namespace InfControls {

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Collections.Specialized;

/// <summary>
/// infFile is the basic file upload option. It is a composite
class
/// consiting of the file upload object itself as well as some
/// basic information underneath it as well about what has been
uploaded
/// or not as the case may be.
/// </summary>
[ValidationPropertyAttribute("Text")]
public class infFile : Control, INamingContainer,
IPostBackDataHandler {

// make _name accessible at any point.
string _name;
string _filepath;

public infFile(string name) {
_name = name;
}

/// <summary> create an instance and set the file path
/// as well </summary>
public infFile(string name, string filepath) {
_name = name;
_filepath = filepath;
}

private void upload_click(Object sender, EventArgs e) {

//Button clicked = (Button)sender;

//HtmlInputFile thefile =
(HtmlInputFile)FindControl(_name + "_up");

this.Text += "this is a test";
}

protected override void CreateChildControls() {

// set up the controls we want.
LiteralControl text;
LiteralControl disptext;

// used for the actual file to be uplaoded on
HtmlInputFile file = new HtmlInputFile();
file.ID = _name + "_up";
Controls.Add(file);

// add the button that does the upload
Button uploadbtn = new Button();
uploadbtn.ID = _name + "_btn";
uploadbtn.Text = "Upload";
uploadbtn.Click += new EventHandler(upload_click);
Controls.Add(uploadbtn);

// add some text surrounding it all.
text = new LiteralControl("<br/>");
Controls.Add(text);

// so now depending on whether we
if (_filepath== "") {
disptext = new LiteralControl("No file has been
uploaded");
Controls.Add(disptext);
} else {
disptext = new LiteralControl("Currently uploaded:
");
Controls.Add(disptext);

HyperLink hl = new HyperLink();
hl.Text = _filepath;
hl.NavigateUrl = _filepath;
hl.Target = "newwin";
Controls.Add(hl);
}
}

// define some public methods etc to maintain state.
public string Text {
get {
if (ViewState["value"] == null)
return String.Empty;
return (string) ViewState["value"];
}
set {
ViewState["value"] = value;
_filepath = value;
}
}

// this is where we implement the iPostBackDataHandler
Interface
bool IPostBackDataHandler.LoadPostData( string postDataKey,
NameValueCollection
postCollection) {

Text = postCollection[postDataKey];
return false;
}

void IPostBackDataHandler.RaisePostDataChangedEvent(){}
}
}



As can be seen in the constructor, I am adding the event without any
drama and there doesn't seem to be a problem with it in the compiler.
It just doesn't seem to be firing in the page when I click on the
button.

In the form when it displays, it shows up in the right spot, the form
is submitted and a post back is done and no text appears in the label I
am using to manage the text with.

I know I am doing something wrong because the test case using design
controls works great - but where I am going wrong, I have no idea so
any help would be greatly appreciated.

Cheers
AndrewF

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom WebControl with OnClick event Tomasz J Microsoft ASP .NET 3 3rd Oct 2007 03:32 PM
Custom Composite Control and Validators Rick Microsoft ASP .NET 4 6th Jun 2007 08:34 AM
Capture an Event in a composite control From control on a page gdick@kerrhenderson.com Microsoft ASP .NET 1 10th Aug 2006 05:17 PM
Composite Custom Controls - The Event Horizon Mr Newbie Microsoft ASP .NET 1 6th Nov 2005 03:30 PM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com Microsoft ASP .NET 0 1st Jul 2003 10:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:33 AM.