i have developed a gridview control. which as searching, paging ,sorting, as a Functionality. i have made this control as a user control. in the page where i am using the user control. i need to add check box inside the user control[GRIDVIEW].
right now i am assigning the bound fields like this
<uc1:GridUserControl ID="GridUserControl1" runat="server" Header1 ="User " Datafield1 ="User_Name" Header2="First Name" Datafield2 ="First_Name" Header3 ="Last Name" Datafield3 ="Last_Name" />
now is there any way we can add our control's inside the User control [gridview ]
can any one let me know how to achive this
thank you
You can get at a usercontrol's child controls using
myUserControlInstance.FindControl("ChildControlID")
but you probably don't want to. This is rather fragile, due to the lack of compile-time checking. If the control was renamed (or refactored into another control for reuse),this would start failing at runtime.
I recommend either a property on the user control that exposes the checkbox, or enough properties/methods on the user control to set the checkbox's state.
You may also want to consider why the parents need to know about the innards of the usercontrol. I usually treat a control's children as analogous to private/protected methods on a class. Hide the implementation details, so you can change them if required!
Related
I am making a template using Usercontrol in WPF(C#).
However, when applying this user control, is it possible to subtract a specific part? For example, removing a button?
To substract specific parts from UserControl, Visibility (Collapse, Hidden) option can be used.
Make sure to add dependency property in UserControl for Visibility to show & hide specific part.
It sounds like you are just trying to hide an existing button, which you should do by setting Visibility to Visibility.Collapsed or Visibility.Hidden. This should be done through a binding to the ViewModel of your user control.
If you need a pure XAML solution: No it is not possible as such. However, the reverse is possible: you can add content to a user control, and that effectively provides the same functionality.
What you could do is make a base user control that doesn't contain the button, and instead has a content presenter. A second user control could wrap the base user control and define a button as its content. Then when you don't want to use the user control with the button you can simply create an instance of the base user control.
In my app, there is a feature to customize it's own Controls (like Textbox, Labels, Textblocks, Buttons, etc), this feature interface is located inside a TabItem. Lets say i want to modify Button A, which is located in ANOTHER container. On the feature interface, i set it's Foreground property to White, at this moment i don't know whether the Button looks better or not, so i have to go to the container which contains that Button.
What am i trying to do is, i want to create a "preview" Control (which is the same type as the actual target) inside the feature interface. I want any changes on this "preview" control are reflected to the actual target Control. With this, i won't need to navigate to where the target Control located.
When i used the title ("How do you bind 2 controls)" with google, all results actually gives me "how to bind SINGLE property of a control to another control's property". What i want is how do you bind/link 2 Controls literally, i mean, i want to bind ALL properties of Control A to ALL properties of Control B.
Binding them one by one is one (tiring) way. Is there another way to achieve this?
I would prefer code-behind method.
There is no "fast" way to do this, you will have to bind one by one according to your buisness logic.
Also a binding is not cheap regarding performance so binding each and every property of a control even those you dont explicitly need, is a warning sign.
I have multiple controls in my User controls like
text box, drowndown, listview , gridview and etc.
I have set some property in usercontrols which set enable and visible property of each control.
like isdropdownvisible, istextboxvisible and etc.
But I want those control which are set visible=false does not get initialized. so that processing.
Or suggest me another method which can enhance page speed
Since part of the initialization itself is the setting of the visible flag, i.e. the system does not know whether a control is visible or not until after it is initialized, I'm afraid what you ask for is not only impossible, but illogical as well.
If you have a problem that some controls have too heavy initializations, that are not needed immediately, you can load them in some dynamic manner, but I could not be more specific, without some example code.
I have a "cross section" of variables that I need to use to generate a set of user controls dynamically. In the center of the page I have a Telerik multitab/page. I have a custom tree menu and a custom menubar, based on the combination of menu input each of the tabs should load a user control relevant to that cross section of data.
For clarity, almost each tab, treeview, menubar combination needs a unique control.
My problem is that all the postback/loading happens well before the "OnMenuChanged" event triggers, so I'm one "set" of user controls behind. Even if I were to use session/viewstate they wouldn't get assigned until after I needed the value stored in them.
Currently what is happening is the default user controls are loaded in the "pageviewcreated" event, then in the onMenuItemChanged I go back and reload the user controls. It seems very inefficient and is complicating up the approach for selecting the right .ascx.
How do I manage this?
If I understand what you're trying to do could you not use a placeholder control and inject your needed usercontrol into that inside of the events you're managing? Try doing something like this inside of the "OnMenuSelected" event.
WebUserControl1 uc = (WebUserControl1) Page.LoadControl("WebUserControl1.ascx");
PlaceHolder1.Controls.Add(uc);
Hopefully I am stating that right. I have a WinForm(3.5) app that has 1 Form that is broke into two regions. 1 is the Navigation and the other, a Panel, is the Content. You select what you want in the Navigation Portion, i.e. Demographics, and then it embeds a UserControl containing all the Demographics controls in the Panel.
What I am asking is if each User Control should have a Property for each Control on it. Example: ucDemographics has a textbox, named txtCity. Should there be a Property to store the value of txtCity and allow my Form and other User Controls to access it?
Is that the generally accepted 'Best Practice'?
If not, what is?
It depends on what you want to achieve with your UserControl.
Normally you wouldn't expose the txtCity because the caller could manipulate everything about the textbox then. In most scenarios, you would only expose the current text รก la
public string CityText
{
get { return this.txtCity.Text; }
}
No, that's not really a best practice. The intention of a user control is to compose a new control with its own behavior. You should at most have "several" properties, methods and events that are public and allows a form to interact with the new control. If you find that the only good way to work with it is by exposing its constituent controls that you're better off not using a UserControl but just place the controls on the form directly.