Reference Web Control Controls From Another Web Control?
Oct 22, 2010
I have 2 controls within my master page that I am using. One is to display user information (which is static), and the other is to display basic data associated with that user (which is not static)
I am trying to use the page load of the non-static control to activate a panel within the static control, rather than activating the static control everytime I do a page load.
So I have the following structure:
[code]....
Currently I am using the Page content to control the control 1 and control 2.
Instead of repeating that code on every page content page, can I make control 2 deal with control 1 or vice versa?
View 2 Replies
Similar Messages:
Sep 16, 2010
MSDN documentation says that the ScriptManager class is part of the System.Web.UI namespace and I see that I can create a ScriptManager object programmatically. However, I don't see the ScriptManager control on the front-end. Do I need to reference the Ajax Control Toolkit dll in order to have access to control?
View 6 Replies
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
Feb 17, 2011
I am trying to assign user control from another user control ..first time its binding control successfully but when we refresh the data its giving error
saying "Object reference is not set an instance".
how to refresh data from another user control ...
My senerio below :
1 Aspx page
2. User control
calling usercontrol databinding method from aspx page but once it get refreshed ,not allowed to bind it again..
View 2 Replies
Feb 8, 2010
I'm trying to programatically reference a FileUpload control which I have within an ItemTemplate. I get a 'Name FileUpload1 is not declared' error message. Code below:
Code is as follows:
[Code]....
[Code]....
View 7 Replies
Jan 29, 2010
I wish to know if it is possible to directly reference a control's value within an SQL Command? I remeber seeing something that caught my attention at one time, but I can't seem to remember where I found it. I am just trying to see if this method could work without having to declare parameters. Here is a sample idea of what I am trying to use:
[Code]....
View 6 Replies
Sep 19, 2010
I am trying to implement adding a new record using the Gridview footer.
I have an example that works finethat I got from [URL]
My situation is a little different .. as I am using master page and the Gridview is in a page derived from the master page.
I have tried:
Dim txtNewName As TextBox = DirectCast(GridView1.FooterRow.FindControl("NewName"), TextBox)
"NewName" is the ID of the textbox in the footer of the Gridview.
When I try referencing ... txtNewName.Text ... it returns a null value.
There must be some trick to referencing this .Text value when using the Gridview that is within a Content Place Holder that results when using a page that was created using a master page.
View 4 Replies
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
Jun 10, 2013
I have created a web user control. It contains a table that has several image buttons. I want them to behave link a tab control. Here's the souce view:
Code:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ProcessMenuContrl.ascx.vb" Inherits="ProcessMenuContrl" %>
<table >
<tr>
<td><asp:ImageButton ID="imgCustomerInformation" runat="server" CausesValidation="false" ImageUrl="~/Images/TabButton_CustomerInformation.jpg" /></td>
[Code] ....
From another page, I have placed this user control into the main content of the form. I have registered it at the top of the page:
Code:
<%@ Register src="ProcessMenuContrl.ascx" tagname="ProcessMenuContrl" tagprefix="uc1" %>
Here's portion of the source where you can see the control is placed under the MainContent of the page. :
Code:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<link href="Styles/QuoteStyles.css" rel="stylesheet" type="text/css" />
<uc1:ProcessMenuContrl ID="ProcessMenuContrl1" imgOrderInformation="" runat="server" />
When the user saves information that's on a form from this same page, I want to enable one of the image buttons (imgOrderInformation).
The problem is that i don't know how to reference this image button that's on the user control.
I've been trying to use Findcontrol, but must be doing it wrong.
View 15 Replies
Apr 20, 2010
I'm not even sure if this is the correct approach for this -
I have a DB that stores information, as well as a location to where images are stored
ie ProductImage = ~/ProductImages/BulkRetail.JPG
I'm using a repeater to list all the products, which works fine for all the labels I use but not for the image location. I'm using something like this, but it doesn't work:
<asp:Image runat="server" ImageAlign="Left" ImageUrl='<%# Eval("ProductImage") %>' />
View 2 Replies
Apr 21, 2010
can you please help me to brainstorm the possible causes of this error. I've got a paged repeater with localisation bound programitcally to an sqldatasource using a stored proc. I can post code if needs be but it's rather long. I'm looking for typical causes of this error + will make note for future reference!
erver Error in '/WebSite4' Application.
Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
[Code]....
Line 233:Line 234: Repeater1.DataSource = PagedResultsLine 235: Repeater1.DataBind()Line 236: doPaging()Line 237: End Sub
View 9 Replies
Nov 24, 2010
Here is data binding expression (dropdown list is nested in gridview)
[Code]....
Code Behind has function which looks like
[Code]....
The whole reason for passing the reference is to save round trip to database and not to use SESSION
View 4 Replies
Mar 11, 2010
my user control i m calling the web service i added script manager in the web page how to add service reference in user control
View 2 Replies
Mar 20, 2011
I'm writing a program that inserts controls onto a webform dynamically. Depending on a variable, I add either a textbox, a set of radio buttons, or a set of checkboxes. Later, after a user clicks a submit button I need to use the controls to determine if the user is submitting the correct answer, but when I try to reference the id of a control, I get "txtAnser is not declared. It may be inaccessible due to it's protections level.
Here is the .aspx page (it's the standard content page of a master page):
[Code].....
View 2 Replies
Sep 16, 2010
how user controls can communicate with each other within an asp.net application. I am facing many obstacles at the moment regarding this problem. For example, is it possible to set the visible property of a panel on one user control based on what happens in another?
Another example would be: Can I set the text of a label in one control to be the value of some other property from another control's class like.... Me.PreContentColumn.ColumnID = LocalProduct.PreContentColumnId.
View 3 Replies
Oct 28, 2010
I'm getting an "Object Reference Not Set to an Instance Of An Object Error" in a Web User Control that I've created when referencing any control in the Code Behind. Intellisense reports that the control exists in the aspx, but whenever I build and run I get that error.
[Code]....
Initially, the error occurs on this line...
[Code]....
View 11 Replies
Oct 18, 2010
I need reference a Treeview from a shared sub so I can run a databind on it after the the sub has finished doing it's thing.
View 3 Replies
Sep 24, 2010
[Code]....
I am getting error of in Foreach loop
[Code]....
How to resolve this situation or any other alternative to cum out of this problem.
View 6 Replies
Jun 10, 2010
I have just asked which one is better?Static Vs Non-Static? [URL]I would like to take this discussion one step ahead.Consider If i pass reference of Panel control as parameter to Public static method, will static method still rules in performance?
View 1 Replies
Aug 24, 2010
I have an ASP.NET web form that has a "container" usercontrol that hosts several custom user controls on the page. The controls can be hosted directly in the container or can be children of other usercontrols. The container usercontrol has several public properties exposed that I sometimes need to get to from within the child user controls. I've been using some form of "this.Parent" or "this.Parent.Parent" to get back to the base control.
What would be the impact of storing a reference to "this" into Session from the base control so I can access it from within the event handlers within the user controls?
View 1 Replies
Oct 7, 2010
How do you reference an asp.net control on your page inside a function or a class.
private void PageLoad(object sender, EventArgs e)
{
//An example control from my page is txtUserName
ChangeText(ref txtUserName, "Hello World");
}
private void ChangeText(ref HtmlGenericControl control, string text)
{
control.InnerText = text;
}
Will this actually change the text of the txtUserName control?
I tried this and is working
private void PageLoad(object sender, EventArgs e)
{
ChangeText(txtUserName, "Hello World");
}
private void ChangeText(TextBox control, string text)
{
control.Text = text;
}
View 2 Replies
Jul 15, 2010
i am trying to enter a value into a texbox that is placed inside a user control called CollectionRequest. i have referenced this user control in my code behind and created an instance of it but i seem to get the above error when i try to enter some manual text. code as follows:
protected CollectionRequest collReq;
protected void Page_Load( object sender, EventArgs e )
{
collReq = (CollectionRequest)LoadControl("~/CollectionRequest.ascx");
TextBox _txt_address = (TextBox)collReq.FindControl("txt_Address");
_txt_address.Text = "thisi is an address";
control has been referenced in source file
<%@ Reference Control="~/CollectionRequest.ascx"%>
i am caling this code in my Approval.ascx.cs code. both the user controls are displayed together in the default.aspx page one above the other.
View 11 Replies
Sep 21, 2010
I am having a problem with rendering a menu control inside a server control. I am getting an error in the RenderContents override method when I try to render the Menu Control. The error I am getting is an Object Reference error. The code is below...
[Code]....
View 7 Replies
Feb 2, 2010
Here is the contents of my test.ascx file:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="test.ascx.cs" Inherits="UserControls_test" %>
<p id="XXX">aaa</p>
and here is the contents of my test.ascx.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UserControls_test : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.XXX.InnerHtml = "BBB";
}
}
I get an error when I refer to the id, "XXX" (underlined above) in code behind which reads: 'UserControls_test' does not contain a definition for 'XXX' and no extension method 'XXX' accepting a first argument of type 'UserControls_test' could be found (are you missing a using directive or an assembly reference?)
I have tried XXX.InnerHtml and I have tried this.XXX.InnerHtml and get same problem.
How do I successfully refer to ID'ed HTML elements in code behind?
View 2 Replies
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