I have a custom control that renders different controls based on a property value. This all works correctly until i try and add a rating control to the control. When i render both controls in the CreateChildControls the control is rendered properly.
However when i try to add layout by overriding the RenderContents method and rendering controls there, an error is generated Extender controls may not be registered after PreRender.The code shows both methods of creating the controls.
I have a user control with both an UpdatePanel and a ScriptManager.
Some pages in the system have a ScriptManager of their own, and need to include the UserControl.
This throws the "You can only have 1 ScriptManager" exception.
If I remove UserControl's ScriptManager, I'll get 'UpdatePanel1 requires a Script Manager" exception.
I've tried to modify the UserControl to dynamically include it's own script manager if none exists. But all the methods I've used before involve adding a delegate to Page.OnInit-- which won't work, since the UserControl Init fires first.
Because the system designers here like making my life difficult, I can't create a MasterPage, or a BasePage for the system in inherit off of. I'd be stuck going to each page an adding a ScriptManager before the UserControl on each of them. Is there any way of, in the UserControl, detecting if the page has a ScriptManager, and if not, adding it dynamically in a way that makes the UpdatePanel happy?
Can anybody explain why cant you have more than one scriptmanager control in a page. Why gets emitted in the markup which creates a problem with two scriptmanager control on the page.
I am reading about "Registering Client Scripts with the ScriptManager Control". But I am not getting what means by registering the script with ScriptManager? What we get by registering the client script with ScriptManager?
I am trying to included a rating control in a composite control that renders many different type of controls. I render the controls by overriding the rendercontents so that I can control the layout of the controls. When I try to add the rating control to the output i get a Page cannot be null error. Can someone provide me with the proper way to render a rating control from a composite control and be able to control the layout of the child controls.
i create a composite control as can be seen in code below, and add this control to webform, assign FormView1 to the HeaderControlName property, Run the page, the system will generate parse error message : Cannot create an object of type 'System.Web.UI.WebControls.FormView' from its string representation 'FormView1' for the 'HeaderControlName' property. However, if i don't assign FormView1 in design screen and manually (through coding) assign FormView1 to the custom control on init, it works as expected.
custom control public class CmdTest : CompositeControl { public virtual FormView HeaderControlName { get { object oObject = ViewState["HeaderControlName"]; return (oObject == null) ? null : (FormView)oObject; } set { ViewState["HeaderControlName"] = value; } } protected override void CreateChildControls( { Controls.Clear(); Button xx = new Button(); Controls.Add(xx); } } webpage.aspx (assign FormView1 in design time, it will generate error) <Utils:CmdTest ID="CmdTest1" runat="server" HeaderControlName="FormView1" /> webpage.aspx (didn't assign FormView1 in ASPX, but assign it on Init Code, it works) <Utils:CmdTest ID="CmdTest1" runat="server" oninit="CmdTest1_Init" /> Webpage.aspx.cs protected void BsCmdTest1_Init(object sender, EventArgs e) { CmdTest1.HeaderControlName = FormView1; }
I am learning custom controls and just finished my first one. The problem is that I am struggling to register it in my web config and have the compiler recognize it. Right now this results in a YSOD about the reference to the control.
note: exact error - Error Unknown server tag 'cc:LblTextBox'.
Web Config
//.. //.. <pages> <controls> <add tagPrefix="cc" namespace="Controls.Server"/> </controls> </pages> </system.web> The control code-behind namespace Controls.Server { public class LblTextBox : CompositeControl { //... } } mark-up <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ControlsMain.aspx.cs" Inherits="Pages_ControlsMain" Trace="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Controls Area</title> </head> <body> <form id="form1" runat="server"> <div> First attempt at a simple composite control <br /> <cc:LblTextBox ID="ccLblTbHybrid" runat="server" LabelText="Name:" /> </div> </form> </body>
I am creating a composite control that has a textbox and uses a jquery plugin to add a watermark. Lets say I have a basic function that looks like this
$(function () {$('#MyTextBoxID').watermark('Enter your username');});
Can anyone suggest what I need to do to insert the above?
If a composite server control normally encapsulate styling information inside, it is an example of code encapsulation and modularization. However if css properties are included inside the composite control, it is not ideal for code/styling separation and css code re-use principles. Now which consideration should be the main consideration?
I have a composite control that has a couple of private fields that reference values in the cache and these private fields are called during the constructor method. Since a string key is used to identify the value in the cache, I must have a way of storing that string key in such a way that it is available at the time the control is instantiated, and I have to be able to reference it on postbacks without it changing.
In addition, this key is generated the first time the control is loaded, but it should not be changed again after that first time.
How can I accomplish this?
I have already tried saving it to viewstate, but that doesn't work because viewstate is not yet available at the time the control is instantiated.
I have tried using a private field and then checking against Page.IsPostback in the constructor and if it isn't postback, I assign a value to the private field, but on subsequent postbacks it looses it's value, and I can't reassign it in the Page.IsPostBack again because it is an autogenerated GUID.
In our current ASP.Net Webforms application we have several composite/template server controls that only exist for a common look and feel. For example, we have a panel control that has a title, a place for buttons related to the contents of the panel, and of course the contents. How is this best accomplished in MVC? RenderPartial doesn't get done what I need here. Should I still be using the same controls, but just on a view page? These controls don't really do anything on postback, they are only there for a common look and feel.
More Info:
We have a control in Webforms that implements ICompositeControl. We have a few properties on this control like Panel (type Panel), Buttons (again type Panel which would hold buttons) and a property Title of type string. Visually it looks like
I am trying to make a simple composite control - just a label and textbox - but the postback isn't being picked up by the control.I haven't implemented IPostBackDataHandler as according to this its not necessary - the TextBox control should tie in automagically. A composite control that includes a TextBox need not worry about postbacks, as the embedded control will work it out with ASP.NET automatically.
I want to develop composite control where some of the work would be executed on client side. For that I am implementing IScriptControl.
ScriptReference points to a script file with client object.
Let's say I want it to have Listview(html select) control that onselect will run javascript function based on the selected value.
I can't just create the control dynamically is client js, because the control has UI on design mode so I must create the select control on server side (I create it in override void Render)
My problem how and where to assign the onselect event for the selection.
Update: Maybe I should add select's id as property to ScriptControlDescriptor, then in client control retrieve this id and attach the needed handler to the event?
I have got a composite control and i would like to dictate which attribute/property is assigned to the control first from the markup?example in the aspx file:
when the control gets created from the mark-up above, ViewType will be assigned first, Which is what I do not want, I would like RealBase to be assigned first under all circumstances. This control is to be users by other developers so I cannot just switch the order.
After this, the text box continues to work correctly, but the _state member does not pick up the posted back values and instead just sticks to the declared value. I've checked the raw posted values in the Request object, and the new value for the list's UniqueID is there, but _state doesn't pick it up.