Search Results

Search found 91 results on 4 pages for 'webcontrol'.

Page 1/4 | 1 2 3 4  | Next Page >

  • Selectively disabling WebControl elements

    - by NeilD
    I have an ASP.Net MasterPage with a PlaceHolder element. The contents of the PlaceHolder can be viewed in two modes: read-write, and read-only. To implement read only, I wanted to disable all inputs inside the PlaceHolder. I decided to do this by recursively looping through the controls collection of the PlaceHolder, finding all the ones which inherit from WebControl, and setting control.Enabled = false;. Here's what I originally wrote: private void DisableControls(Control c) { if (c.GetType().IsSubclassOf(typeof(WebControl))) { WebControl wc = c as WebControl; wc.Enabled = false; } //Also disable all child controls. foreach (Control child in c.Controls) { DisableControls(child); } } This worked fine, and all controls are disabled... But then the requirement changed ;) NOW, we want to disable all controls except ones which have a certain CssClass. So, my first attempt at the new version: private void DisableControls(Control c) { if (c.GetType().IsSubclassOf(typeof(WebControl))) { WebControl wc = c as WebControl; if (!wc.CssClass.ToLower().Contains("someclass")) wc.Enabled = false; } //Also disable all child controls. foreach (Control child in c.Controls) { DisableControls(child); } } Now I've hit a problem. If I have (for example) an <ASP:Panel> which contains an <ASP:DropDownList>, and I want to keep the DropDownList enabled, then this isn't working. I call DisableControls on the Panel, and it gets disabled. It then loops through the children, and calls DisableControls on the DropDownList, and leaves it enabled (as intended). However, because the Panel is disabled, when the page renders, everything inside the <div> tag is disabled! Can you think of a way round this? I've thought about changing c.GetType().IsSubclassOf(typeof(WebControl)) to c.GetType().IsSubclassOf(typeof(SomeParentClassThatAllInputElementsInheritFrom)), but I can't find anything appropriate!

    Read the article

  • How can I include additional markup within a 'Content' inner property within an ASP.Net WebControl?

    - by GenericTypeTea
    I've searched the site and I cannot find a solution for my problem, so apologies if it's already been answered (I'm sure someone must have asked this before). I have written a jQuery Popup window that I've packaged up as a WebControl and IScriptControl. The last step is to be able to write the markup within the tags of my control. I've used the InnerProperty attribute a few times, but only for including lists of strongly typed classes. Here's my property on the WebControl: [PersistenceMode(PersistenceMode.InnerProperty)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public something??? Content { get { if (_content == null) { _content = new something???(); } return _content; } } private something??? _content; Here's the HTML Markup of what I'm after: <ctr:WebPopup runat="server" ID="win_Test" Hidden="false" Width="100px" Height="100px" Modal="true" WindowCaption="Test Window" CssClass="window"> <Content> <div style="display:none;"> <asp:Button runat="server" ID="Button1" OnClick="Button1_Click" /> </div> <%--Etc--%> <%--Etc--%> </Content> </ctr:WebPopup> Unfortunately I don't know what type my Content property should be. I basically need to replicate the UpdatePanel's ContentTemplate. EDIT: So the following allows a Template container to be automatically created, but no controls show up, what's wrong with what I'm doing? [PersistenceMode(PersistenceMode.InnerProperty)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public ITemplate Content { get { return _content; } set { _content = value; } } private ITemplate _content;

    Read the article

  • How can I include additional markup within a 'Content' inner property of an ASP.Net WebControl?

    - by GenericTypeTea
    I've searched the site and I cannot find a solution for my problem, so apologies if it's already been answered (I'm sure someone must have asked this before). I have written a jQuery Popup window that I've packaged up as a WebControl and IScriptControl. The last step is to be able to write the markup within the tags of my control. I've used the InnerProperty attribute a few times, but only for including lists of strongly typed classes. Here's my property on the WebControl: [PersistenceMode(PersistenceMode.InnerProperty)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public something??? Content { get { if (_content == null) { _content = new something???(); } return _content; } } private something??? _content; Here's the HTML Markup of what I'm after: <ctr:WebPopup runat="server" ID="win_Test" Hidden="false" Width="100px" Height="100px" Modal="true" WindowCaption="Test Window" CssClass="window"> <Content> <div style="display:none;"> <asp:Button runat="server" ID="Button1" OnClick="Button1_Click" /> </div> <%--Etc--%> <%--Etc--%> </Content> </ctr:WebPopup> Unfortunately I don't know what type my Content property should be. I basically need to replicate the UpdatePanel's ContentTemplate. EDIT: So the following allows a Template container to be automatically created, but no controls show up, what's wrong with what I'm doing? [PersistenceMode(PersistenceMode.InnerProperty)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public ITemplate Content { get { return _content; } set { _content = value; } } private ITemplate _content; EDIT2: Overriding the CreateChildControls allows the controls within the ITemplate to be rendered: protected override void CreateChildControls() { if (this.Content != null) { this.Controls.Clear(); this.Content.InstantiateIn(this); } base.CreateChildControls(); } Unfortunately I cannot now access the controls within the ITemplate from the codebehind file on the file. I.e. if I put a button within my mark as so: <ctr:WebPopup runat="server" ID="win_StatusFilter"> <Content> <asp:Button runat="server" ID="btn_Test" Text="Cannot access this from code behind?" /> </Content> </ctr:WebPopup> I then cannot access btn_Test from the code behind: protected void Page_Load(object sender, EventArgs e) { btn_Test.Text = "btn_Test is not present in Intellisense and is not accessible to the page. It does, however, render correctly."; }

    Read the article

  • Omit Properties from WebControl Serialization

    - by Laramie
    I have to serialize several objects inheriting from WebControl for database storage. These include several unecessary (to me) properties that I would prefer to omit from serialization. For example BackColor, BorderColor, etc. Here is an example of an XML serialization of one of my controls inheriting from WebControl. <Control xsi:type="SerializePanel"> <ID>grCont</ID> <Controls /> <BackColor /> <BorderColor /> <BorderWidth /> <CssClass>grActVid bwText</CssClass> <ForeColor /> <Height /> <Width /> ... </Control> I have been trying to create a common base class for my controls that inherits from WebControl and uses the "xxxSpecified" trick to selectively choose not to serialize certain properties. For example to ignore an empty BorderColor property, I'd expect [XmlIgnore] public bool BorderColorSpecified() { return !base.BorderColor.IsEmpty; } to work, but it's never called during serialization. I've also tried it in the class to be serialized as well as the base class. Since the classes themselves might change, I'd prefer not to have to create a custom serializer. Any ideas?

    Read the article

  • ASP.NET WebControl ITemplate child controls are null

    - by tster
    Here is what I want: I want a control to put on a page, which other developers can place form elements inside of to display the entities that my control is searching. I have the Searching logic all working. The control builds custom search fields and performs searches based on declarative C# classes implementing my SearchSpec interface. Here is what I've been trying: I've tried using ITemplate on a WebControl which implements INamingContainer I've tried implementing a CompositeControl The closest I can get to working is below. OK I have a custom WebControl [ AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), DefaultProperty("SearchSpecName"), ParseChildren(true), ToolboxData("<{0}:SearchPage runat=\"server\"> </{0}:SearchPage>") ] public class SearchPage : WebControl, INamingContainer { [Browsable(false), PersistenceMode(PersistenceMode.InnerProperty), DefaultValue(typeof(ITemplate), ""), Description("Form template"), TemplateInstance(TemplateInstance.Single), TemplateContainer(typeof(FormContainer))] public ITemplate FormTemplate { get; set; } public class FormContainer : Control, INamingContainer{ } public Control MyTemplateContainer { get; private set; } [Bindable(true), Category("Behavior"), DefaultValue(""), Description("The class name of the SearchSpec to use."), Localizable(false)] public virtual string SearchSpecName { get; set; } [Bindable(true), Category("Behavior"), DefaultValue(true), Description("True if this is query mode."), Localizable(false)] public virtual bool QueryMode { get; set; } private SearchSpec _spec; private SearchSpec Spec { get { if (_spec == null) { Type type = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Name == SearchSpecName).First(); _spec = (SearchSpec)Assembly.GetExecutingAssembly().CreateInstance(type.Namespace + "." + type.Name); } return _spec; } } protected override void CreateChildControls() { if (FormTemplate != null) { MyTemplateContainer = new FormTemplateContainer(this); FormTemplate.InstantiateIn(MyTemplateContainer); Controls.Add(MyTemplateContainer); } else { Controls.Add(new LiteralControl("blah")); } } protected override void RenderContents(HtmlTextWriter writer) { // <snip> } protected override HtmlTextWriterTag TagKey { get { return HtmlTextWriterTag.Div; } } } public class FormTemplateContainer : Control, INamingContainer { private SearchPage parent; public FormTemplateContainer(SearchPage parent) { this.parent = parent; } } then the usage: <tster:SearchPage ID="sp1" runat="server" SearchSpecName="TestSearchSpec" QueryMode="False"> <FormTemplate> <br /> Test Name: <asp:TextBox ID="testNameBox" runat="server" Width="432px"></asp:TextBox> <br /> Owner: <asp:TextBox ID="ownerBox" runat="server" Width="427px"></asp:TextBox> <br /> Description: <asp:TextBox ID="descriptionBox" runat="server" Height="123px" Width="432px" TextMode="MultiLine" Wrap="true"></asp:TextBox> </FormTemplate> </tster:SearchPage> The problem is that in the CodeBehind, the page has members descriptionBox, ownerBox and testNameBox. However, they are all null. Furthermore, FindControl("ownerBox") returns null as does this.sp1.FindControl("ownerBox"). I have to do this.sp1.MyTemplateContainer.FindControl("ownerBox") to get the control. How can I make it so that the C# Code Behind will have the controls generated and not null in my Page_Load event so that developers can just do this: testNameBox.Text = "foo"; ownerBox.Text = "bar"; descriptionBox.Text = "baz";

    Read the article

  • In an asp.net, how to get a reference of a custom webcontrol from a usercontrol?

    - by AJ
    Hi I have a page which holds a custom webcontrol and a usercontrol. I need to reference of webcontrol in usercontrol class. So, I make the declaration of webcontrol as public in page class. But, when I do “this.Page.”, I don’t see the webcontrol listed in list provided by intellisense. Most probably, I am missing something. In an asp.net page, how to get a reference of a custom webcontrol from a usercontrol? Please advise. Thanks Pankaj

    Read the article

  • Problem with ScriptManager.RegisterStartupScript in WebControl nested in UpdatePanel

    - by Chris
    Hello, I am having what I believe should be a fairly simple problem, but for the life of me I cannot see my problem. The problem is related to ScriptManager.RegisterStartupScript, something I have used many times before. The scenario I have is that I have a custom web control that has been inserted into a page. The control (and one or two others) are nested inside an UpdatePanel. They are inserted onto the page onto a PlaceHolder: <asp:UpdatePanel ID="pnlAjax" runat="server"> <ContentTemplate> <asp:PlaceHolder ID="placeholder" runat="server"> </asp:PlaceHolder> ... protected override void OnInit(EventArgs e){ placeholder.Controls.Add(Factory.CreateControl()); base.OnInit(e); } This is the only update panel on the page. The control requires some initial javascript be run for it to work correctly. The control calls: ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), script, true); and I have also tried: ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), script, true); The problem is that the script runs correctly when the page is first displayed, but does not re-run after a partial postback. I have tried the following: Calling RegisterStartupScript from CreateChildControls Calling RegisterStartupScript from OnLoad / OnPreRender Using different combinations of parameters for the first two parameters (in the example above the Control is Page and Type is GetType(), but I have tried using the control itself, etc). I have tried using persistent and new ids (not that I believe this should have a major impact either way). I have used a few breakpoints and so have verified that the Register line is being called correctly. The only thing I have not tried is using the UpdatePanel itself as the Control and Type, as I do not believe the control should be aware of the update panel (and in any case there does not seem to be a good way of getting the update panel?). Can anyone see what I might be doing wrong in the above? Thanks :)

    Read the article

  • Registering custom webcontrol inside mvc view?

    - by kastermester
    I am in the middle of a project where I am migrating some code for a website from WebForms to MVC - unfortunatly there's not enough time to do it all at once, so I will have to do some... not so pretty solutions. I am though facing a problems with a custom control I have written that inherits from the standard GridView control namespace Controls { public class MyGridView : GridView { ... } } I have added to the web.config file as usual: <configuration> ... <system.web> ... <pages> ... <controls> ... <add tagPrefix="Xui" namespace="Controls"/> </controls> </pages> </system.web> </configuration> Then on the MVC View: <Xui:MyGridView ID="GridView1" runat="server" ...>...</Xui:MyGgridView> However I am getting a parser error stating that the control cannot be found. I am suspecting this has to do with the mix up of MVC and WebForms, however I am/was under the impression that such mixup should be possible, is there any kind of tweak for this? I realise this solution is far from ideal, however there's no time to "do the right thing". Thanks

    Read the article

  • Asp net aspx page and webcontrol issue

    - by Josemalive
    Hello, I have a class that inherits from Page, called APage. public abstract class APage: Page { protected Repeater ExampleRepeater; .... protected override void OnLoad(EventArgs e) { if (null != ExampleRepeater) { ExampleRepeater.DataSource = GetData(); ExampleRepeater.DataBind(); } base.OnLoad(e); } } For other hand i have an aspx page called Default that inherits from this APage: public partial class Default : APage { } on the design part of this Default page, i have a repeater: <asp:Repeater ID="ExampleRepeater" runat="server"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "Name") %><br/> </ItemTemplate> </asp:Repeater> This repeater is datasourced at the base APage load event, but at this level this web control is null. Do you have any idea why the control is null in the base page? Thanks in advance. Best Regards. Jose.

    Read the article

  • asp.net free webcontrol to display crosstab or pivot reports with column and row grouping, subtotals

    - by dev-cu
    Hello, I want to develop some crosstab also know as pivot reports in Asp.net with x-axis and y-axis being dynamics, allowing grouping by row and column, for example: have products in y-axis and date in x-axis having in body number of sells of a given product in a given date, if date in x-axis are years, i want subtotals for each month for a product (row) and subtotals of sells of all products in date (column) I know there are products available to build reports, but i am using Mysql, so Reporting Service is not an option. It's not necessary for the client build additional reports, i think the simplest solution is having a control to display such information and not using crystal report (which is not free) or something more complex, i want to know if is there an available free control to reach my goal. Well, does anybody know a control or have a different idea, thanks in advance.

    Read the article

  • asp.net free webcontrol to display matrix reports with column and row grouping, subtotals and totals

    - by dev-cu
    Hello, I want to develop some kind of reports in Asp.net with x-axis and y-axis being dynamics, allowing grouping by row and column, for example: have products in y-axis and date in x-axis having in body number of sells of a given product in a given date, if date in x-axis are years, i want subtotals for each month for a product (row) and subtotals of sells of all products in date (column) I know there are products available to build reports, but i am using Mysql, so Reporting Service is not an option. It's not necessary for the client build additional reports, i think the simplest solution is having a control to display such information and not using crystal report (which is not free) or something more complex, i want to know if is there an available free control to reach my goal. Well, does anybody know a control or have a different idea, thanks in advance.

    Read the article

  • Invoking code both before and after WebControl.Render method

    - by Dirk
    I have a set of custom ASP.NET server controls, most of which derive from CompositeControl. I want to implement a uniform look for "required" fields across all control types by wrapping each control in a specific piece of HTML/CSS markup. For example: <div class="requiredInputContainer"> ...custom control markup... </div> I'd love to abstract this behavior in such a way as to avoid having to do something ugly like this in every custom control, present and future: public class MyServerControl : TextBox, IRequirableField { public IRequirableField.IsRequired {get;set;} protected override void Render(HtmlTextWriter writer){ RequiredFieldHelper.RenderBeginTag(this, writer) //render custom control markup RequiredFieldHelper.RenderEndTag(this, writer) } } public static class RequiredFieldHelper{ public static void RenderBeginTag(IRequirableField field, HtmlTextWriter writer){ //check field.IsRequired, render based on its values } public static void RenderEndTag(IRequirableField field, HtmlTextWriter writer){ //check field.IsRequired , render based on its values } } If I was deriving all of my custom controls from the same base class, I could conceivably use Template Method to enforce the before/after behavior;but I have several base classes and I'd rather not end up with really a convoluted class hierarchy anyway. It feels like I should be able to design something more elegant (i.e. adheres to DRY and OCP) by leveraging the functional aspects of C#, but I'm drawing a blank.

    Read the article

  • What is the best WebControl to create this

    - by balexandre
    current output wanted output current code public partial class test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) populateData(); } private void populateData() { List<temp> ls = new List<temp>(); ls.Add(new temp { a = "AAA", b = "aa", c = "a", dt = DateTime.Now }); ls.Add(new temp { a = "BBB", b = "bb", c = "b", dt = DateTime.Now }); ls.Add(new temp { a = "CCC", b = "cc", c = "c", dt = DateTime.Now.AddDays(1) }); ls.Add(new temp { a = "DDD", b = "dd", c = "d", dt = DateTime.Now.AddDays(1) }); ls.Add(new temp { a = "EEE", b = "ee", c = "e", dt = DateTime.Now.AddDays(2) }); ls.Add(new temp { a = "FFF", b = "ff", c = "f", dt = DateTime.Now.AddDays(2) }); TemplateField tc = (TemplateField)gv.Columns[0]; // <-- want to assign here just day gv.Columns.Add(tc); // <-- want to assign here just day + 1 gv.Columns.Add(tc); // <-- want to assign here just day + 2 gv.DataSource = ls; gv.DataBind(); } } public class temp { public temp() { } public string a { get; set; } public string b { get; set; } public string c { get; set; } public DateTime dt { get; set; } } and in HTML <asp:GridView ID="gv" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("a") %>' Font-Bold="true" /><br /> <asp:Label ID="Label2" runat="server" Text='<%# Eval("b") %>' Font-Italic="true" /><br /> <asp:Label ID="Label3" runat="server" Text='<%# Eval("dt") %>' /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> What I'm trying to avoid is repeat code so I can only use one unique TemplateField I can accomplish this with 3 x GridView, one per each day, but I'm really trying to simplify code as the Grid will be exactly the same (as the HTML code goes), just the DataSource changes. Any help is greatly appreciated, Thank you.

    Read the article

  • C# syntax to get access to webcontrol in different file (aspx)

    - by Josh
    Within my Website project, I have some aspx pages, javascript files, and a custom C# class I called MyCustomReport. I placed a Image box with an ID of Image1 inside SelectionReport.aspx. I need to get access to that Image1 inside MyCustomReport.cs so I can turn it on and off based on conditions. What code do I need to do this? Thanks everyone

    Read the article

  • CreateChildControls AFTER Postback

    - by Francois
    I'm creating my own CompositeControl: a collection of MyLineWebControl and a "add" button. When the user press the "add" button, a new MyLineWebControl is added. In CreateChildControls(), I run through my model (some object MyGridOfLines which has a collection of MyLine) and add one MyLineWebControl for each MyLine. In addButton.Click, I add a new MyLine to my object MyGridOfLines. But, since the Click event method is called after CreateChildControls(), the new MyLineWebControl will be only displayed on the next postback. What can I do to "redraw" immediately my control, without loosing values that I've entered in each input?

    Read the article

  • Web User Control og Event

    - by Mcoroklo
    I have a web user control, CreateQuestion.ascx, in ASP.NET. I want an event "QuestionAdded" to fire when a specific button is clicked. I don't want to send any data, I just want to know WHEN the button is fired. My implementation: CreateQuestion.ascx: public event EventHandler QuestionAdded; protected virtual void OnQuestionAdded(EventArgs e) { if (QuestionAdded != null) QuestionAdded(this, e); } /// This is the button I want to know when is fired protected void SubmitButton_Click(object sender, EventArgs e) { //question.Save(); this.OnQuestionAdded(new EventArgs()); } On the page AnswerQuestion.aspx, I use this: private void SetupControls(int myId) { CreateQuestionControl.QuestionAdded += new EventHandler(QuestionAdded); } private void QuestionAdded(object sender, EventArgs e) { Response.Write("HEJ KARL?"); } My problem No matter what, the event is never fired. I know that both SetupControls() is being run, and the code behind the button which should fire the event is run. When I debug, I can see the event QuestionAdded always are null. How do I make this work? Thanks a lot

    Read the article

  • Sitecore development. Sitecore.Web.UI.WebControl.GetCacheKey() throws NullReferenceException

    - by user344010
    I just click submit button and got an exception. Unable to debug, because this happens before the submit event handler work. I tried to clear sitecore caches, browser caches and cookies... nothing helps. here the stack trace. [NullReferenceException: Object reference not set to an instance of an object.] Sitecore.Web.UI.WebControl.GetCacheKey() +242 Sitecore.Web.UI.WebControl.Render(HtmlTextWriter output) +61 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.HtmlControls.HtmlHead.RenderChildren(HtmlTextWriter writer) +17 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.Page.Render(HtmlTextWriter writer) +29 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

    Read the article

  • Why don't all System.Web.UI.WebControl classes with Text properties implement ITextControl?

    - by jrummell
    I'm curious why only some System.Web.UI.WebControl controls implement certain interfaces when they have the same properties of an interface. For instance, there are plenty of controls that have a Text property but only the following implement ITextControl: Label Literal DataBoundLiteral TextBox ListControl (TextBox and ListControl actually implement IEditableTextControl which implements ITextControl) TableCell, Button, HyperLink and others don't so I have to write code like this ITextControl textControl = control as ITextControl; TableCell tableCell = control as TableCell; if (textControl != null) { textControl.Text = value; } else if (tableCell != null) { tableCell.Text = value; } instead of this control.Text = value; Was this a design decision or an oversight?

    Read the article

  • How to enable ajax when deriving from System.Web.UI.WebControls.WebControl on controls that are crea

    - by Dave
    I've built a class that derives from System.Web.UI.WebControl. It basically renders pagination links (same as what you see on top of GridView when enabled) for use above a repeater. I'm creating some anchor tags explicitly inside my nav control obviously, but they don't perform ajax postbacks. My understanding is that ajax requires POSTS to work right? Well, these would be GETs which I think is the problem. Is there a way to achieve what I'm trying to do? Thanks!

    Read the article

  • SharePoint: Problem with BaseFieldControl

    - by Anoop
    Hi All, In below code in a Gird First column is BaseFieldControl from a column of type Choice of SPList. Secound column is a text box control with textchange event. Both the controls are created at rowdatabound event of gridview. Now the problem is that when Steps: 1) select any of the value from BaseFieldControl(DropDownList) which is rendered from Choice Column of SPList 2) enter any thing in textbox in another column of grid. 3) textchanged event fires up and in textchange event rebound the grid. Problem: the selected value becomes the first item or the default value(if any). but if i do not rebound the grid at text changed event it works fine. Please suggest what to do. using System; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace SharePointProjectTest.Layouts.SharePointProjectTest { public partial class TestBFC : LayoutsPageBase { GridView grid = null; protected void Page_Load(object sender, EventArgs e) { try { grid = new GridView(); grid.ShowFooter = true; grid.ShowHeader = true; grid.AutoGenerateColumns = true; grid.ID = "grdView"; grid.RowDataBound += new GridViewRowEventHandler(grid_RowDataBound); grid.Width = Unit.Pixel(900); MasterPage holder = (MasterPage)Page.Controls[0]; holder.FindControl("PlaceHolderMain").Controls.Add(grid); DataTable ds = new DataTable(); ds.Columns.Add("Choice"); //ds.Columns.Add("person"); ds.Columns.Add("Curr"); for (int i = 0; i < 3; i++) { DataRow dr = ds.NewRow(); ds.Rows.Add(dr); } grid.DataSource = ds; grid.DataBind(); } catch (Exception ex) { } } void tx_TextChanged(object sender, EventArgs e) { DataTable ds = new DataTable(); ds.Columns.Add("Choice"); ds.Columns.Add("Curr"); for (int i = 0; i < 3; i++) { DataRow dr = ds.NewRow(); ds.Rows.Add(dr); } grid.DataSource = ds; grid.DataBind(); } void grid_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { SPWeb web = SPContext.Current.Web; SPList list = web.Lists["Source for test"]; SPField field = list.Fields["Choice"]; SPListItem item=list.Items.Add(); BaseFieldControl control = (BaseFieldControl)GetSharePointControls(field, list, item, SPControlMode.New); if (control != null) { e.Row.Cells[0].Controls.Add(control); } TextBox tx = new TextBox(); tx.AutoPostBack = true; tx.ID = "Curr"; tx.TextChanged += new EventHandler(tx_TextChanged); e.Row.Cells[1].Controls.Add(tx); } } public static Control GetSharePointControls(SPField field, SPList list, SPListItem item, SPControlMode mode) { if (field == null || field.FieldRenderingControl == null || field.Hidden) return null; try { BaseFieldControl webControl = field.FieldRenderingControl; webControl.ListId = list.ID; webControl.ItemId = item.ID; webControl.FieldName = field.Title; webControl.ID = "id_" + field.InternalName; webControl.ControlMode = mode; webControl.EnableViewState = true; return webControl; } catch (Exception ex) { return null; } } } }

    Read the article

  • Weird exception in linkbutton in a datalist

    - by user308806
    Dear all, I have written this datalist : <div class="story" runat="server"> <asp:DataList ID="DataList2" runat="server" Height="16px" Width="412px"> <SeparatorTemplate> <hr /> </SeparatorTemplate> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat ="server" Text='<%# Eval("Name") %>' PostBackUrl='<%#Eval("Url")%>' /> <br /> Description: <asp:Label ID="new" Text='<%#Eval("Description") %>' runat="server" /> </ItemTemplate> </asp:DataList> </div> It raises an exception saying that the linkbutton has to be placed in a tag that contains runat="server" although it exists. Here is the trace [HttpException (0x80004005): Le contrôle 'DataList2_ctl00_LinkButton1' de type 'LinkButton' doit être placé dans une balise form avec runat=server.] System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +8689747 System.Web.UI.WebControls.LinkButton.AddAttributesToRender(HtmlTextWriter writer) +39 System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +20 System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +20 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +10 System.Web.UI.WebControls.DataListItem.RenderItemInternal(HtmlTextWriter writer, Boolean extractRows, Boolean tableLayout) +51 System.Web.UI.WebControls.DataListItem.RenderItem(HtmlTextWriter writer, Boolean extractRows, Boolean tableLayout) +57 System.Web.UI.WebControls.DataList.System.Web.UI.WebControls.IRepeatInfoUser.RenderItem(ListItemType itemType, Int32 repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer) +64 System.Web.UI.WebControls.RepeatInfo.RenderVerticalRepeater(HtmlTextWriter writer, IRepeatInfoUser user, Style controlStyle, WebControl baseControl) +262 System.Web.UI.WebControls.RepeatInfo.RenderRepeater(HtmlTextWriter writer, IRepeatInfoUser user, Style controlStyle, WebControl baseControl) +27 System.Web.UI.WebControls.DataList.RenderContents(HtmlTextWriter writer) +208 System.Web.UI.WebControls.BaseDataList.Render(HtmlTextWriter writer) +30 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.Page.Render(HtmlTextWriter writer) +29 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

    Read the article

1 2 3 4  | Next Page >