C# - Add Reference To Method In Custom Control To A Child Control Created In That Same Custom Control

Feb 3, 2010

I have a custom control that is based off the gridview control located at: here The control is basically a gridview that automatically creates a column of checkboxes that can be used to "check" individual rows in the gridview. During the gridview's "CreateColumns" event, the "checkboxcolumn" is created dynamically. The checkboxcolumn also contains another checkbox in the header that is used to "select/deselect all" checkboxes in the column. Since the gridview does not automatically remember the state of the checkboxes in the checkboxcolumn on postback, I added a method to the control called "SaveCheckBoxState" which stores the indexes of the checked rows in Viewstate, and then I modified the "OnRowDataBound" event to check the Viewstate and reset the checkboxes based on the Viewstate.

I then added a call to "SaveCheckBoxState" in the gridview's OnSorting and OnPageIndexChanging events. This works great so long as I'm sorting or changing pages. However, I need it to update the viewstate everytime someone clicks or unclicks one of the checkboxes. At this time, the checkboxes are rendered with an onclick event that calls some javascript to highlight the row, or in the case of the checkbox in the header, to select/deselect all checkboxes. I need to call the "SaveCheckBoxState" method from the javascript used by the customcontrol, or I need to find a way to modify viewstate from javascript and perform the same action as "SaveCheckBoxState".

I've tried adding the "SaveCheckBoxState" to the onclick event declaration in the checkboxes, but when run, it simply tells me that the method is undefined. It doesn't exist in the parent page, and I don't think I should have to make an event for the parent page to pass the click to. It seems to me this should be all self contained within the custom control. Does anyone know how I can acheive this? Here is the code for the gridview OnPreRender event where the onclick event of the checkbox is set:

protected override void OnPreRender(EventArgs e)
{
// Do as usual
base.OnPreRender(e);
// Adjust each data row
foreach (GridViewRow r in Rows)
{
// Get the appropriate style object for the row
TableItemStyle style = GetRowStyleFromState(r.RowState);
// Retrieve the reference to the checkbox
CheckBox cb = (CheckBox)r.FindControl(InputCheckBoxField.CheckBoxID);
// Build the ID of the checkbox in the header
string headerCheckBoxID = String.Format(CheckBoxColumHeaderID, ClientID);
// Add script code to enable selection
cb.Attributes["onclick"] = String.Format("ApplyStyle(this, '{0}', '{1}', '{2}')",
SelectedRowStyle.CssClass,
style.CssClass,
headerCheckBoxID);
// Update the style of the checkbox if checked
if (cb.Checked)
{
r.BackColor = SelectedRowStyle.BackColor;
r.ForeColor = SelectedRowStyle.ForeColor;
r.Font.Bold = SelectedRowStyle.Font.Bold;
}
else
{
r.BackColor = style.BackColor;
r.ForeColor = style.ForeColor;
r.Font.Bold = style.Font.Bold;
}
}
}

View 1 Replies


Similar Messages:

C# - Add Child Nodes To Custom User Control Derived From System.Web.UI.Control?

Sep 4, 2010

I would like to know how to add some additional child nodes to a custom user control class derived from System.Web.UI.Control. For example currently I have a control that contains no child nodes and on the design surface looks like the following.

<cust:MyCustomControl id="ctlMyCustomControl" runat="server" attribute1="somevalue" attribute2="somevalue" ></MyCustomControl>

What I am looking for is to have the ability to add n number of child nodes to this control from the design surface and then access their values from the code. So adding to the control stated above.

<cust:MyCustomControl id="ctlMyCustomControl" runat="server" attribute1="somevalue" attribute2="somevalue" >
<childnode1>value1</childnode1>
<childnode2>value2</childnode2>
</MyCustomControl>

It is not clear to me how to access the child nodes.

View 2 Replies

Custom Server Controls :: Custom Composite Control With Custom Templated Child Controls?

Mar 22, 2011

I am trying to build a custom composite control, which allows me to add custom content to each child control. It's a similar concept to what you have with a GridView and TemplateColumn. The markup used to place the control on the page would end up being something like this:

[Code]....

I have the code below, which allows me to put that markup on the page without throwing any errors, and it renders all the correct HTML, except it doesn't render the contents of the ColumnTemplate. I have replaced the Render() code with a comment because it's quite long winded and doesn't add anything important here:

[Code]....

I have tried to follow examples on MSDN and other forums but I can't make this work. I think I'm missing the code to render the contents of the template, but I don't know how to hook that up.

View 1 Replies

Custom Server Controls :: Hide A Method While Creating Custom Control By Inheriting WebControl?

Nov 29, 2010

I am creating a custom control by inheriting a server control, say LinkButton. There are properties like "BorderColor" available in LinkButton. Let's say, I don't want this particular property to be available when I create an instance of the custom control.

I want to completely hide this particular property (I don't want to override it but disable it.)

My code is as follows:

[Code]....

View 3 Replies

Web Forms :: Override Custom Method In Custom Control?

Feb 17, 2011

I have created a custom control as can be seen below. this custom control will be used by alot of web form. The question is how to override CheckAllData method in each webform, so i can write my own checking in each webform.

[Code]....

View 5 Replies

Custom Server Controls :: Custom Control's Constructor / User To Set That variable In The Properties Window After They Drag The Control Onto A Form?

Mar 4, 2010

I have a custom control which inherit from the Table class and in the constructor, it takes a an integer as an argument. There is no empty constructor.

Is there a way for the user to set that variable in the properties window after they drag the control onto a form.

I know some .NET controls, you can set the source for the parameter to different things like another control's property, QueryString using just the properties window.

Right now, I have to create the control dynamically. I read the query string and then created the object.

View 1 Replies

Custom Server Controls :: Paging And Sorting Gridview Custom Control Inside Of A Wizard Control?

Dec 24, 2010

here's a situation and I would appreciate your response.

I have programmatically created the Wizard control:

Page_Load(obj s, evargs e)
{
Wizard ClaimDetailWizard = new Wizard();
foreach(int item in selectedItems)
{
//create new step
//added custom control to new step
//add step to wizard
}
//added wizard to a placeholder on a page
}

Based on List I get from Session i added new steps to my wizard To each step I had added a custom control

Each custom control in tern contains another custom Gridview Control in it.

So here's the problem when the page loads for example for two steps. All is good Wizard does what it's supposed to do.

But when I try to use sorting or paging in that custom Gridview. Somehow it displays the gridview I should see in the next step of the wizard.

Also what I'm noticing through debugging. Is that when I press next in the wizard I go back to the original page where I do all of the code specified above, and it recreates the wizzard. But it goes to the next step. Is this the way wizard supposed to work? Just doesn't seem very efficient.

View 1 Replies

Custom Server Controls :: Add This Control To The Page,an Alert To Check The Text Value Of The Custom Control?

Dec 20, 2010

created a Custom Textbox Control that is intended to be a "masked date" textbox, so that I can handle different ways a user might enter in a date and make it work no matter what.I did this by creating a custom control with 3 separate Textboxes one for month,one for day one for year,then do some handling for different things that could be entered and it would all work.

The problem I am having is,when I add this control to the page,if I do an alert to check the Text value of the custom control it just gives me "[ServerControl1]" even if I enter in a date.

I tried doing an AutoPostback after entering so that it would refesh the Viewstate to have the values of the textboxes but the control doesnt seem to actually postback, even though I have it enabled.accessing the Textbox value after someoen
has entered a date?first custom control I have created and have been using google.

My Server Control Code is as follows:

[Code]...

View 1 Replies

Custom Server Controls :: Unable To Convert User Control To Custom Control

Oct 27, 2010

I have created a user control and am ready to convert it into a custom control. I am trying to follow:

[URL] the steps mentioned in the link.

I am not seeing Build / Publish Web Site option.

I am using VS 2008. I only see Publish User Control but it doesn't give all the settings mentioned below. When I do publish user control, it just copies the ascx file to the desired location. how can I convert the user control to custom control.

View 2 Replies

Accessing Property Value Of A Custom Control By Another Custom Control In Design-time

Oct 18, 2010

I created an Extender which has a custom property that drills down a list XML elements from an xml file, where users can select xml elements during design-time. This works perfectly fine. However, my code only has a hardcoded xml filename (source of the xml elements list) and I need to change this by maxing the xml file user-specified.

What I did is that I created another control (panel) which has a custom property that when clicked (through the ellipsis), it will allow a developer to select the xml file which is supposed to be the source xml file that the Extenders shall use. The filedialog from custom panel's property works perfectly fine.

However, my problem now is that when I drag-drop my Extender, I cannot find a way to get the property value of the custom Panel Control which contains the xml filename. I tried creating a static variable which I thought the custom controls can share but VS2010 is breaking.

View 4 Replies

Custom Server Controls :: Custom Server Control Rendering Method In Multiple Class?

May 17, 2010

I am creating custom server control. I have two classes in project. One is main class that render control and another will be used to render content based on condition.I just want to know how to render content from other classes in main class.For example. This isjust an example.My main class code

[Code]....

My TopLeftPane class

[Code]....

My page code on page load event

[Code]....

When I run the page, Header title always getting null. This is a just sample code. I will have more than 20 classes so I dont want to write a code in main class to render whole control.I hope all of you understand my problem.

View 3 Replies

Custom Server Controls :: Use Custom Control/user Control?

Oct 12, 2010

I have 3 pages in each page there is a portion of page where it is common in all these three pages.Thought of making the common stuff as a separate control either User control/Custom control.Any suggestions on which one should i use custom/user control

View 2 Replies

How To Expose Child Control Style Properties In A Custom Composite WebControl

Feb 23, 2010

I am writing a custom composite WebControl and want to expose styles of child controls it encapsulates to the ASP.NET designer. The code I currently have is similar to the skeleton below (which for simplicity only has one child control).

With the code below, I can see property "ChildPanelStyle" in the designer, but when I try to modify one of the properties (e.g. CssClass) in the designer, it immediately resets itself to its default value. It looks like the designer serialization isn't happening.

What am I doing wrong?

UPDATE

I've updated the sample with an additional style property that is managed directly by the custom control, rather than simply being the property of a child control.

The HeaderStyle property is persisted properly by the designer, but the ChildPanelStyle property isn't.

Of course I could manage all my styles like HeaderStyle, and apply them during rendering, but I'm hoping there's a simpler solution whereby child controls can take care of themselves, and I don't need any custom rendering.

[code]....

View 1 Replies

Web Forms :: Access Parent Control Method From Child Control?

Jun 23, 2010

I have a parent control and a child control. On parent control load I am setting a cookie value. On child control I am checking if this cookie is not null then call parent control's CalculateDeliveryAndTax() method. How should I go about accessing from child control, parent control's CalculateDeliveryAndTax() method.

View 2 Replies

Custom Control Rendering In Designer With Object Reference Error

Jan 2, 2011

I created a custom server control. The control works perfectly when added into a project. The issue I have though, is that in the designer - it shows the error --> "Error creating control - MyControl1 Object Reference not set to an instance of an object" The error is because I am using this code to load startup scripts

Dim pg As Page = HttpContext.Current.Handler

if i comment it out then the designer does not throw the object reference error so I know this is where the problem is. So here is my question: How can I get the designer to ignore the HttpContext.Current.Handler object for rendering puroposes?

View 2 Replies

Web Forms :: Register Or Add Reference Custom Control In Web Confige File?

Dec 25, 2010

I have one Custom Control! I add reference in pages Like Below <%@ Register TagPrefix="cus" Namespace="Controls" %> at Run time There is No error ! Error Shown at deploy Time Unknown server tag 'cus:GridHeaderFilter'. My custom control is in App_Code folder With Name GridHeaderFilter.vb So How To add Or Register This Custom Control In web confige File

View 1 Replies

Web Custom User Control Threw A Null Reference Exception?

Mar 8, 2010

I' m using a web custom control to upload images and mark them as primary. all the flow is working fine but it fails to mark images as primary in a diffrent category(there are four categories in which we can load a image-,catalog,primary,misc).It works in - category but not in others when I debug it is failing at a condition in grey . If it is not an element of the Datalist item it would not even enter the loop. I' m lost and unable to find the reason.

View 2 Replies

AJAX :: Created A Custom Validation Control That Compares Two Textboxes And Verifies Their Content?

Jul 19, 2010

I recently created a custom validation control that compares two textboxes and verifies their content. When I use this control in a detailsview I have no problems but, when an updatepanel is added the validation control no longer works.I'm using Visual Studio 2010 and .net 3.5 framework.

View 5 Replies

Web Forms :: Custom Control Can Add Click In The Control Codebehind But Not When Using The Control

Feb 16, 2011

ive created my own custom control, now in the code behind of the custom control file i can add Name.Click += new EventHandler(name); but on the codebehind of the page where ive used the custom control i cannot, is there anyway i can regsiter it as an available attribute to add? my code below and on the image the test codebehind click is not available, how can i get it?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class LargeButton : System.Web.UI.UserControl
{
public string JSFunc { get; set; }
public string SSFunc { get; set; }
public string ImgName { get; set; }
public string LinkText { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
Link.Attributes.Add("onclick", "javascript:"+ JSFunc + ";");
Link.HRef = "javascript:;";
Link.Title = LinkText;
Img.Src = "~/App_Themes/" + Page.Theme + "/Images/Icons32/" + ImgName;
Img.Alt = LinkText;
//Link.ServerClick += new EventHandler(asd);
}
}
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="LargeButton.ascx.cs" Inherits="LargeButton" %>
<a ID="Link" runat="server" class="MenuItemLarge" clientidmode="Static" >
<img ID="Img" align="center" runat="server"/>
<br />
<%= LinkText %>
</a>
<MB:LgButton runat="server" ID="Save"
JSFunc="Save(this)"
ImgName="save_32.png"
LinkText="Save" />

View 4 Replies

Web Forms :: Refresh A Gridview In A Custom Control From The Method Of Another?

Apr 12, 2010

I am looking for a way to refresh one custom control inside a method of another. Here is what I have:

A.aspx <- contains (B,C) custom controls below

B.ascx <- adds data to SQL databaseC.ascx <- contains (D) custom control below

D.ascx <- shows data from SQL database

Data is added to SQL in the C# B.ascx code-behind method. Upon a new row being added I would like a GRIDVIEW inside the D.ascx control to refresh and show that new record immediately.

Initially I had all the code on the same page, but then needed to cut it into separate custom controls. The code worked perfectly fine before and now I need this refresh to happen again. The code I used before to refresh the gridview was like this:

// sqlSummary.DataBind();
// grdSummary.DataBind();

In the end I also need to update the screen. I used an UpdatePanel before, but no longer have it. Not sure what the best way to update the screen is with the new data.

View 7 Replies

Custom Server Controls :: How To Reference A Control Defined In The Code Behind From The Aspx File

Jul 1, 2010

I have the following Report class that I want to serve as the base class for my pages.

I will have several aspx files MyReport1.aspx, MyReport2.aspx, ... MyReportN.aspx

---------
Report.cs
---------

public class Report : Page
{
protected readonly ListView reportListView; [code]....

View 3 Replies

Custom Server Controls :: User Template Control Or Custom Server Control?

Jul 22, 2010

I need to develop control (template or user) which must have subtags with some items.

For example :

<SomeControl runat="server" id="scTest">
<column1>TestColumn1</column1>
<column1>TestColumn1</column1>
<column1>TestColumn1</column1>
</SomeControl>

This control may contain some other web server controls such as GridView.I need explanation of experienced developers, how to do that - take me to the right way

View 3 Replies

Custom Server Controls :: Custom Tag Not Found For Control / Error: Unknown Server Tag 'custom:AjaxValidator'

Jan 3, 2011

Hope this is the correct forum for this question. I am using VWD 2010 an have a web project and get the following error upon execution:

Parser Error Message: Unknown server tag 'custom:AjaxValidator'.

My code is as follows in the .cs file:

[Code]....
[Code]....

View 1 Replies

Does A Composite Server Control(inc. User Control, Custom Server Control) Normally Encapsulate Css Properties?

Nov 7, 2010

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?

View 2 Replies

To Create A Custom Control That Adds Other Controls Visible To The Page Hosting My Custom ?

Oct 22, 2010

I want to create a custom control where I define several specifically named DIV sections. The code-behind logic of the custom control will perform operations on these named DIV sections. The page where the custom control is hosted needs to be able to add named controls to the DIV sections and perform operations on these named controls added to the DIV sections.

Let me explain a little further. In the custom control, I want to have code behind logic that fires the following Page Event and uses a condition to make one or another specifically named DIV section visible or not:

< _
ToolboxData("<{0}:BaseDetails runat=""server""></{0}:BaseDetails>") _
> _
Public Class BaseDetails

[code]...

how can I create a custom control which is able to generate the named DIV sections "DetailsNameDiv1" and "DetailsNameDiv2" where my custom control can check a condition and make one or the other visible. Also, I need to be able to add controls to these named DIV sections when I host the custom control and the control that I add to the named DIV section needs to let me set values of these controls from the code behind logic of the page (or usercontrol) where the custom control is being hosted (in my example, I am adding TextBox controls that I want to set the Text property from a SQL Data Reader).

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved