custom web user control and web form

Guys,

         I am trying to develop a context menu control for all of my pages. what i am trying to do is that i want the control to pick a datasource from the markup and then check whether its an xml file or a datatable. I created a class called datasource.

 

/**************************DataSource Class****************************/

 

public class DataSource {

/// <summary>

/// This is to identify unique elements from the markup

/// </summary>

protected string _ID;

/// <summary>

/// This will be the Datasource ID either XML file or the DataTable

/// </summary>

protected object_name;

/// <summary>

/// This property is for the Sequence of the DataSource ID's

/// </summary>

protected int _sequence;

private TypeConverter instance=TypeDescriptor.GetConverter(new object());

public DataSource(){

 

}

public string ID{

get{

return _ID;

}

set{_ID = value;

}

}

public object Name{

get{

return _name;

}

set{_name =value;

 

}

}

 

 

 

public int Sequence{

get{

return _sequence;

}

set{_sequence = value;

}

}

}//end DataSource

 

/********************************************DataSourceCollection Object*******************************/

public class DataSources : CollectionBase {public DataSources(){

}

/// <summary>

/// Summary: Gets an System.Collections.ArrayList containing the list of elements in the System.Collections.CollectionBase instance. Returns: An System.Collections.ArrayList representing the System.Collections.CollectionBase instance itself.Retrieving the value of this property is an O(1) operation.

/// </summary>

 

public void Add(DataSource item)

{

InnerList.Add(item);

}

public DataSource this[int index]

{

get { return (DataSource) InnerList[index]; }set { InnerList[index] = value; }

}

public void AddAt(int index, DataSource item)

{

InnerList.Insert(index, item);

 

}

public void Sort()

{

InnerList.Sort(
new DataSourceComparer());

}

 

}//end DataSources

public class DataSourceComparer: IComparer

{

public int Compare(object x,object y)

{

DataSource s1= (DataSource) x;

DataSource s2= (DataSource)y;

return s1.Sequence.CompareTo(s2.Sequence);

}

}

/************************************ContextMenu*************************/

[ParseChildren(true, "DataSources")]

[DefaultProperty("DataSources")]

public class ContextMenu : WebControl, INamingContainer {

/// <summary>

/// Collection of the Datasources from the markup

/// </summary>

protected DataSources _dataSources;

/// <summary>

/// CssClass for the ASP:Image control

/// </summary>

protected string _menuImageCssClass;

/// <summary>

/// CssClass for the ASP:HyperLink Control

/// </summary>

protected string _menuTextCssClass;public ContextMenu(){

}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

//[Editor(typeof(ContextMenuItemCollectionEditor), typeof(UITypeEditor))]

[PersistenceMode(PersistenceMode.InnerProperty)]

[TypeConverter(
typeof(DataSource))]

[Description("Gets the collection of the menu items")]

public DataSources DataSources{

get{

if(_dataSources==null)

{

_dataSources=
new DataSources();

}

return _dataSources;

}

set{_dataSources = value;

}

}

public string MenuImageCssClass{

get{

return _menuImageCssClass;

}

set{_menuImageCssClass = value;

}

}

public string MenuTextCssClass{

get{

return _menuTextCssClass;

}

set{_menuTextCssClass = value;

}

}

 

 

I haven't included the render method. To keep it short the problem is when i declare the values in the .aspx page as

<cc1:ContextMenu ID="ContextMenu1" runat="server" >

<cc1:DataSource ID="vamsi" Name=S Sequence=1 />

</cc1:ContextMenu>

            .net throws me an error and it says that string could not be converted in to object. My design should take either xml file or data table from the markup and then process either datatables or xml file and extract our own custom data.

 

thanks

vamsi


 

 

0
vamsikomarneni
2/4/2008 8:33:18 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

1 Replies
1009 Views

Similar Articles

[PageSpeed] 22

vamsikomarneni:
public DataSources DataSources
 

Hi vamsikomarneni,

Base on my experience, there are some error in your code.

See the above line, you can not defined a DataSources like that, this is just one error, maybe there are other error in your code.

Please double check your code, if you still can not solve your problem, let me know. Smile

Thanks. 

Hope it helps,

Hong Gang
 


Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
2/6/2008 7:29:58 AM
Reply:

Similar Artilces:

Web Form and Web User Control
Hello, I have a Web User Control (ascx) that includes a button. This button has an onclick event method. This Web User control is included into a Web Form. (thru LoadControl). However, when I click on the button, the event method is not executed. What should I include in order it works fine? Thanks in advance. GAA. Using Loadcontrol is using dynamic controls and when using dynamic controls you must recreate the same dynamic controls ono postback to econstruct the page control tree. It is best if you do this during the Page PreInit event. How complex are your controls ...

How to access a control on a web form from anoter web form
hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it possible to access lbl1 from form2, change its text permenantly? thanks.   refer: http://dotnetslackers.com/Community/blogs/haissam/archive/2007/11/26/ways-to-pass-data-between-webforms.aspxSSNPlease remember to click "Mark as Answer" on the post that helps you. MinaSamy: hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it p...

Web User Control Not rendering in Web Form
I have created a Web User control that is made up of a Multiview with 2 views inside the Multiview. I have buttons on both views and a gridview on 1 view. My question is when I drop this Web User Control on a Web Form all I see is [MultiView"MultiView1"] and when I view the from in the browser I dont see the Web User Control. I was wondering if someone could please tell me why the Web User Control is not displaying or rendering.     Thanks In Advance Hi, Please check your aspx file for correct reference, like following example: TestControl.ascx:<%@ Control ...

web web web
Name: bahadir Email: sensiz_olmuyor_t1_at_hotmail.com Product: Firefox 2 Beta 2 Summary: web web web Comments: web sayfası yapmak Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.8.1b2) Gecko/20060821 Firefox/2.0b2 ...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

Access a Web User Control Method from a Web Form
I'm trying to pass the Selected Index value from a web user control in a web form to the user controls selectedIndexchanged Sub.  I can't seem to figure out how to pass the information that I need to the user control and have it execute the sub routine. In the SelectedInedxChanged Sub I have a switch Statement and I want to get the index value from the web form where the user control is located and compare it to each case and then to have it execute the code for the case that it matches. What do I need to do? Hi, I am not sure if I understood your question correctly. I su...

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

Interaction between Web User Control & Web form
Ok, I want to create my first Web User Control which is used for file uploading. It's very simple, consist only of the <asp:FileUpload> and <asp:Button> control. The button has one server side event which is resizing the uploaded image to two different images (stored as byte[] in the cs file). So, my question is how I can send these two arrays of type byte to the Web form where the web user control is inside. I thought it should be possible to write something like this in the Web form:<uc1:FileUploader ID="uploader" runat="server" OnUploaded="recieveImages" />So that means ...

Access SqlDataSource on Web Form from a Web User Control...
Hello, I want to access a SqlDataSource on a Web Form fromout. a Web User Control. To do this, I have in my code behind of the Web User Control the folowing code: DropDownList1.DataSource = (this.Page.FindControl("SqlDataSource3") as SqlDataSource);DropDownList1.DataTextField = "Name;DropDownList1.DataValueField = "NameIDropDownList1.DataBind(); But, the control (ic. SqlDataSource3) is not found. Even other controls like labels and buttons are not found with the FindControl. What am I doing wrong? Thanks Andromedaris     This is not much of a surprise,...

Pass data from Web User Control to Web Form
I have a Web Form that contains a Web User Control. The WUC displays dynamic content. I want to change the TITLE property of the Web Form, based on the contents of the WUC. For example, if the WUC displays information about Horses, I want to change the page title to "HORSES" by passing the string to the parent Web Form. I have tried playing with parameters and such, but I can't remember how I did this in the past. PLEASE HELP!~o0 Spin-Monkey Oo~ The best way to do this is by creating a public property on your web user control and accessing that from your web form. Check ...

I cannot drag web custom controls from toolbox to web form
I have created some web custom controls (both composite controls or derived/inherited controls).  I successfully added them to the toolbox. However, when I try to drag them onto the form, the cursor changes into a black circle with a diagonal line, and cannot drag them.  I also tried double-clicking them from the toolbox but it still won't work. I sent the Control Library (DLL) to a friend, and he managed to use it properly.  I am assuming this is a problem with my Visual Studio. Has anyone encountered such a problem?  Any suggestions or solutions?   Thanks. I...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

Cant drag-and-drop Web Custom Control to Web Form!
Hi,I'm going insane here, I've read countless articles how to create a Web Custom Control and add it to the Toolbox and then just Drag-and-Drop it to a Web Form.And I have done exactly that except for the last step, any Web Custom Control I create refuses to be Drag-and-Dopped to the Web Form. What happens is the following, after I have added the Web Custom Control to the ToolBox I click it and drag it to the Web Form designer area. First I can see the icon of the Web Custom Control and I see a Referance being created but just after that the icon changes to one of those "you cant park here s...

Web resources about - custom web user control and web form - asp.net.web-forms

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

ConnectSense Smart Outlet lets Siri control two HomeKit Wi-Fi wall sockets, USB charge iPads
... “smart plugs” previously released by iHome , ConnectSense has debuted the Smart Outlet with Apple HomeKit ($80) , which combines two Siri-controlled ...

How effective are parental controls for your child's safety?
... situation. Parents need to find ways to protect their children when they are not around to monitor it themselves. The Use of Parental Controls ...

Larwyn's Linx: Gun Control Group Calls For Obama To Declare “State of Emergency,” Ban Guns
Send us tips ! Bloggers: install a Larwyn's Linx widget . Get real-time news, 24/7, at BadBlue . Nation Gun Control Group: Obama Must Declare ...

Kurt Vile, Superchunk, Deer Tick, Waxahatchee, Parquet Courts, Sonic Youth members & more celebrated ...
photos by Amanda Hatfield; words by Bill Pearis Parquet Courts & Lee Ranaldo / Rainer Maria & Meredith Graves / Kurt Vile & Kim Gordon / Waxahatche ...

San Bernardino shooting and the politics of gun control
"It's not enough to keep lamenting these things," Democratic Sen.

Kylie Jenner & her very thin Greyhounds were investigated by Animal Control
... healthy (you can see some screencaps from the Snapchats here ). So… Kylie was investigated by the LA County Department of Animal Care and Control. ...

Assad Takes Control Of ‘Capital Of The Revolution’
Another victory for the Syrian government coming weeks after the regime regained control of Kuweires airbase.

Your opinion on gun control doesn't matter
... will die by guns than in car accidents this year. In practice, this is a public health crisis. If you still bristle at the idea of gun control, ...

Amy Schumer Tweets About Gun Control After San Bernardino Mass Shooting: 'It Doesn't Have to Be This ...
Amy Schumer Tweets About Gun Control After San Bernardino Mass Shooting: 'It Doesn't Have to Be This Way'

Resources last updated: 12/3/2015 8:08:15 PM