ScriptControl Client Id Within User Control?
Mar 18, 2011
I've got a custom script control, or what I call a composite control with a client side object, that I'm trying to use within a user control. The problem is the user control is changing the control id. So when I wire up the events with the code below the ids are wrong.
comboBox.OnClientLoad = "function(sender, eventArgs){" + Common.FindScriptObject(this.ClientID) + ".ComboBoxLoad(sender,eventArgs); }";
The Common.FindScriptObject code just outputs $find(''). Because it is being used within a user control the client side ids have an some extra lenght to them, like "usercontrol_controlclientId" vs "controlclientId". So how do I get the ids to be correct within a usercontrol?
View 1 Replies
Similar Messages:
Nov 23, 2010
I have a user control which contains a CustomValidator which is used according to whether a RadioButton is checked or not (there are several RadioButtons, I'm only showing the relevant one)
<asp:RadioButton runat="Server" ID="RadioBetween" GroupName="DateGroup" CssClass="date_group_options_control_radio" />
[code]...
There is some client + server side validation code (the server side code does exactly the same thing and is skipped for brevity)
<script type="text/javascript">
function ValidateDateFields_Client(source, args) [code]...
There are two instances of this control in the page. When running the client side version it hits the wrong one (the version of the control which is disabled). You can see from the generated HTML both are correctly specified. I'm not sure how .NET works out which clientside function to call given they both have the same name.
<script type="text/javascript">
//<![CDATA[
var ctl00_MCPH1_QueryTextValidator = document.all ? document.all["ctl00_MCPH1_QueryTextValidator"] : document.getElementById("ctl00_MCPH1_QueryTextValidator");
[code]...
Do i need to add something in to scope it? What's the best way to achieve this? If I disable the loading of the second control everything works fine.
View 1 Replies
Jun 14, 2010
I have a webdayview control (Infragistics proprietary ASP.net control) on my page. On the aspx source I've inserted some javascript (webdayview_click - clientside click event) that calls a webmethod in the codebehind. This seems to work fine, but when I
insert this webdayview control into a user control and move the corresponding javascript into the aspx of the user control, it doesn't work. I can't even insert a breakpoint into the javascript function to debug it. Is there a way to make it work? I want to enable the click event of the webdayview control so that when I click on it, the javascript function calls the webmethod. Here's my code (remember it is inside a user control):
[code]...
I posted this question on the Infragistics forum but didn't get any replies. Hopefully I'll get some here. :)
View 2 Replies
Feb 28, 2011
Maybe I've picked a totally inappropriate/bad example. What I have is a user control that contains a bunch of dynamically created Telerik RadGrids. My user control is added to a couple of Telerik RadPageViews that are part of a RadMultiPage that is used alongside a RadTabStrip. What I need to do is call a Javascript function in my usercontrol to update it's display whenever it's parent RadPageView is selected.
So basically I have the following Javascript code:
function OnClientTabSelected(sender, args)
{
// Get the MyControl that is on this tab
var myControl = $find("whatever");
// Call a method that updates the display
myControl.doSomething();
}
View 2 Replies
Feb 28, 2011
I am trying to add some client side functionality to a user control that I have written.
A really simplified version of my scenario is as follows:
I have a control called MyControl. This has a javascript method called doSomething that simply shows the current date and time in an alert box.I add an instance of MyControl to a page called WebForm1. I want to be able to call myControl1.doSomething when a regular (non ASP.NET) button on WebForm1 is pressed.
I'm sure this is really simple but I can't for the life of me figure out what I need to do make doSomething available.
View 7 Replies
Aug 13, 2010
I have a user control which has some properties configured on it. I need to access (actually, only read) the values of those properties on the client. I have done it like this.
Code behind:
[Code]....
ASPX:
[Code]....
That works but, at the back of my mind, I'm sure I've seen a neater way of doing it, although I suspect that may have been on an Extender not a User Control. Pointers on that welcome.
Also, related to that, the User Control itself has an Id which becomes part of the name of all visual objects included within it. However, the User Control is not a DOM element in its own right (because it has no visible rendering) which [I think] means that I have to attach properties to one of the visible elements within it, and not to the control itself?
View 2 Replies
Oct 21, 2010
I have a ScriptControl (requires ScriptManager) with JavaScript to handle client-side interactions and ICallbackEventHandler to communicate back and forth. Everything works perfectly with one or multiple instances of the control on a page. I placed the control inside a GridView with sorting and it still works. However, I place the GridView in an UpdatePanel and now whenever I sort I get the following error for each instance:
Sys.InvalidOperationException: Two components with the same id 'GridView_ctl02_MyControl' can't be added to the application.
Can someone point me in the right direction on how to solve this? I am assuming ScriptManager is not disposing of the old Sys.UI.Control objects before trying to $create() the new ones with the same ID. I thought the UpdatePanel/ScriptManager combination would automatically take care of disposing objects that would be replaced?
View 1 Replies
Sep 8, 2010
Is there a client side event that occurs on a user control when its parent submits to the server?
View 1 Replies
Feb 12, 2010
I have a question. How do I correctly derive from a script control? Especially how to correctly define the script descriptors.
Let's say, I have a MyScriptControl class implementing IScriptControl:
[Code]....
In the derived class, how Do I correctly overwrite the GetScriptDescriptors method? Should I just call base.GetScriptDescriptors, enumerate through them and exchange the Type name everywhere? Or is there a more clean feeling approach to that?
View 4 Replies
Oct 20, 2010
I have a ScriptControl that uses an image as an embedded resource and GetWebResourceUrl to generate the WebResource.axd URL. I am currently using GetScriptDescriptors() to send the URL to the JavaScript object.The ScriptControl can be in a Repeater, so you may have 20+ instances. They all use the same images (not customizable through property), so I would like to set the URL once in a variable and share it. I know I could register a script block with a global variable, but would like to avoid that if possible. Is there a way to set a variable within the scope of the control type (global -> control type -> control instance)?
View 1 Replies
Apr 27, 2010
I'm creating a control based on ScriptControl, and I'm overriding the Render method like this:
protected override void Render(HtmlTextWriter writer)
{
RenderBeginTag(writer);
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write("This is a test.");
writer.RenderEndTag();
RenderEndTag(writer);
}
My question is, what if I want to assign the div an ID attribute and have it be unique on the page, even if there are mulitple instances of my control?
I've seen other people's code that does this:
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_divTest");
That will prevent naming conflicts between instances of my control, but what if I've already created a div elsewhere on the page that coincidentally has the same ID?
I've also heard about implementing INamingContainer. Would that apply here? How could I use it?
UPDATE:
I've worked around this by overriding CreateChildControls and adding actual controls, as opposed to rendering HTML directly. In that case INamingContainer does its job. However, I'm still curious if there's a way to solve my original problem (unique IDs for directly rendered elements).
View 3 Replies
Jun 4, 2010
I don't think I understand fully how ASP.NET does inheritance of controls.I have a user control, ucBase, which has an asp.net label in the ascx file. Code behind references the label and it works fine during run time if the control is not a parent for another user parent.
If I have another user control, ucChild, inheriting from ucBase, the label in ucBase's code is always null. ucChild has no controls in its ascx fileThe server controls (like the label) needs to be declared in the ascx file and not created programmatically.What needs to be done for ucBase to see its own controls when it's a parent user control?
View 1 Replies
Sep 10, 2010
I've got a web site that has a master page and that master page (mpMaster that has a user control ucControl1) which has a sub user control (ucControl2), this user control has a property which accepts a value. Now, I have a page that uses the master page
and on this page I have another user control (ucPageControl), I need to find a way of setting the value in ucControl2 from ucPageControl. Is this possible at all?
View 5 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 18, 2011
I'm attempting to create a simple menu user control just as outlined here.
The attached code results in an "Object reference not set to an instance of an object" error, but I can't figure out why.
<%@ Master Language="VB" CodeFile="MySite.master.vb" Inherits="MySite" %>
<%@ Register src="Controls/Menu.ascx" tagname="Menu" tagprefix="my" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">......
View 1 Replies
Jun 11, 2010
I have to access the parent form's controls inside an event handler method on my user control's code behind.
View 4 Replies
Mar 10, 2011
I have a web user control that represents a simple message box. It is used to display simple messages like "Item has been deleted", or "The item was saved successfully".
On the other hand, I have another web user control that represents the item in the form of an editable form (I made this a user control because this is used in two different pages). I want to embed an instance of the message box user control inside the editable form. I am writing this right after the @Control directive:
[Code]....
Instead of using @Register directives, I register the user controls in web.config and so far this has worked just fine.
With the above markup, the project compiles, but whenever I try to navigate to a page that contains this construct, I get an HttpParseException exception. Furthermore, Visual Studio states that the tack w7rc9:MessageBox doesn't represent a known control.
What am I doing wrong?
View 2 Replies
Jul 16, 2010
I want to convert windows user control into web user control..I have the usrDataView.cs..I need to convert this file into usrdataview.ascx.can anyonr help me?...how I can convert the file...Is any method is available..
View 1 Replies
Jun 3, 2010
have two user controls on one aspx page. UC1 has a grid which contains a link button column which user clicks. Based on the value of clicked cell, I need to show some data into UC2.How do I pass data from UC1 to UC2? How do I invoke a function of UC2 from UC1?
View 2 Replies
Apr 16, 2010
All I would like to be able to do is include one user control within another! Is this possible? I have spent the last hour searching the internet and it seems that I can't find a single thing.
In classic ASP it would be something like:
<!--#include file="EditProject.ascx"-->
I tried this but no luck!
Parser Error Message:
There can be only one 'control' directive.
Source Error:
[Code]....
Line 1: <%@ Control Language="VB" AutoEventWireup="false" CodeFile="EditProject.ascx.vb"Line 2: Inherits="Controls_WebUserControl" %>Line 3: <form runat="server">
View 3 Replies
Mar 5, 2011
It's simple to create both user control from the two world : ASP.NET+Razor or MVC 3.0.But i do not known how to consume the user control FROM the razor"_layout.chtml" page.I want to put such thing within the layout page: <uc:MyTag Prop1="" Prop2="" />So i need to declare this directive at top of the layout file : <%@ Register TagPrefix="uc" TagName="MyTag" Src="Controls/Mytag.ascx" %>
View 1 Replies
Jun 7, 2010
I used following methods
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]
Request.ServerVariables["REMOTE_HOST"]
Request.UserHostAddress
Request.UserHostName
All the above are returning "127.0.0.1", not the actual IP.
The below one returns null.
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
Below one always returns where the application is hosted/running, not the client's IP address.
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
View 14 Replies
Feb 26, 2010
I have a user control which contains two text fields each assigned with requiredfield validators this control contains another user control contains say a button .On click of this button i need to validate the fields from the parent control text fields.I try the Page.Validate("ValidationGroup") with Page.IsValid it validates but the error message is not shown .Error message is shown only if i try to validate it from the contains which contains the required field validators ?
View 1 Replies
Jul 13, 2010
Now the weird thing is I have a user control UserControl1 in which I put some JavaScrdipt logic there, and I have another user control UserControl2 and I registered both in the page called Page1.aspx.I would like to call the JavaScript function resided in UserControl1 from UserControl2, however, I got an error saying the function is not defined. I think both user controls are loaded before I use them then I think the JavaScript function can been seen anyway in that page.
View 1 Replies
Mar 22, 2011
i have 2 user control : uc1 and uc2. and i have button in uc2 i call button1, i want to set commandArgument of button1 from uc1, how can i do this?
View 5 Replies