How to set web user control property from client side ?


I've created a web user control and it has some property.

    public partial class MyControl: System.Web.UI.UserControl
        string _PropertyA;

        public string PropertyA
            get { return _PropertyA; }
            set { _PropertyA= value; }

 Is there a way to set this property from client side,  similar to the way i do it on server side (e.g MyControl.PropertyA =...)?


Dont forget to click "Mark as Answer" on the post that helped you
3/25/2008 11:30:35 AM 93655 articles. 5 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 52


this is a solution, but not the nicest one :  

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs"
    Inherits="WebUserControl" %>

<script runat="server">
    public void Page_Load(object sender, EventArgs e)
        Page.ClientScript.RegisterClientScriptInclude(GetType(), "wuc", "wuc.js");

    public string PropertyA
        get { return __PropertyA.Value; }
        set { __PropertyA.Value = value; }

    protected void Page_PreRender(object sender, EventArgs e)
        Page.ClientScript.RegisterStartupScript(GetType(), "wuc_pa", string.Format("WUC.register('{0}');", ClientID), true);
        Page.ClientScript.RegisterOnSubmitStatement(GetType(), "wuc_submit", "WUC.submit();");

<span id="<%= ClientID %>">
    <asp:HiddenField ID="__PropertyA" runat="server" />


var __WUC = function()
    this._array = new Array();
__WUC.prototype.register = function(elementID) 
    var e = document.getElementById(elementID);
    e.PropertyA = document.getElementById(elementID + "___PropertyA").value;
__WUC.prototype.submit = function()
    for(var i = 0; i < this._array.length; i++)
        document.getElementById(this._array[i].id + "___PropertyA").value = this._array[i].PropertyA;
var WUC = new __WUC();
and in your jscript function
document.getElementById("MyControl").PropertyA = "another value";
Something using javascript methods - get_propertyA(), set_propertyA(e) - is probably better, you should post on Client Side Web Development forum.
3/25/2008 7:05:38 PM

use Ajax if u dont want a complete set a server variable u need to go to the server.....becoz if u set it at the client and dont send a post back...the value is not changed effectively.also changing at the browser involves javascript......which means browser compatibilty ......disabled scripts etc etc.....and u dont wanna go there!!

Let the game begin!!

Barcode image generation made easy.
Writing an ActiveX Control in C#
Generating Relational Data From XML Datatype -Part 1
Generating Relational Data From XML Datatype -Part 2
Dynamic XML From SQL Server
3/25/2008 8:42:47 PM

 Thanks guys.

Dont forget to click "Mark as Answer" on the post that helped you
3/25/2008 9:04:01 PM

Similar Artilces:

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Set User Control Property from web form class
I am having a difficult time Setting the values of the properties in my User Control. My user control code follows: '---- tabs.ascx.vb ------------------- Public Class tabs Inherits System.Web.UI.UserControl Public tab1Name As String Public tab1href As String Public Sub New() End Sub Property t1Name() Get Return tab1Name End Get Set(ByVal Value) tab1Name = Value End Set End Property Property t1href() Get Return tab1href ...

Web User Control +Client Side Control
Two Questions if Possible:  1: Some controls have methods/properties that can be gotten/set client-side (IE ASP:Timer).  Can usally access them by "$find('<%=Control.ClientID%>').get_(set_)name()".  I made a User Control that has a "Enabled" Propertiy (basically sets a bunch of its components to "visible = false" and then a Timer.Enabled=false).  I can't access my user controls "enabled" via client side script (IE $find(UserControl.ClientID).set_enabled(false)).  How do I bundle this type of fu...

Web Form and Web User Control
Hello, I have a Web User Control (ascx) that includes a button. This button has an onclick event method. This Web User control is included into a Web Form. (thru LoadControl). However, when I click on the button, the event method is not executed. What should I include in order it works fine? Thanks in advance. GAA. Using Loadcontrol is using dynamic controls and when using dynamic controls you must recreate the same dynamic controls ono postback to econstruct the page control tree. It is best if you do this during the Page PreInit event. How complex are your controls ...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

How to access the properties and methods of the ActiveX control on the client side in Web Form using javascript or vbscript
Hi All, I have looked almost every where for this, and I'll be really appreciated if someone can help me with this. I found a article in MS KB article, #317392, but it is not extactly what I wanted. How do you reference an ActiveX control's methods and properties with javascript in the ASPX? Following is what I have. Some how the following line in the btnclick() does not seems to be working. AlarmCtl.StartTimer() I have done this with just .HTML and it works just fine. Can any one help. Thanks in advance. //===========================...

Web User Control Not rendering in Web Form
I have created a Web User control that is made up of a Multiview with 2 views inside the Multiview. I have buttons on both views and a gridview on 1 view. My question is when I drop this Web User Control on a Web Form all I see is [MultiView"MultiView1"] and when I view the from in the browser I dont see the Web User Control. I was wondering if someone could please tell me why the Web User Control is not displaying or rendering.     Thanks In Advance Hi, Please check your aspx file for correct reference, like following example: TestControl.ascx:<%@ Control ...

custom web user control and web form
Guys,          I am trying to develop a context menu control for all of my pages. what i am trying to do is that i want the control to pick a datasource from the markup and then check whether its an xml file or a datatable. I created a class called datasource.   /**************************DataSource Class****************************/  public class DataSource { /// <summary> /// This is to identify unique elements from the markup /// </summary>protected string _ID; /// <summary> /// This will be the Datasource ID e...

web controls and web user control
i have a problem in a web form , I have a webform that contains a web user control which in turn contains a html input form ,the web control events don't fire up ,When I click button ,no effect ,I don't know what is the effect of the html form which is in the web user control on the web controls in the web form ?? can any one help me the web control event should be handle in the code behind page, is the event handler for the button you are clicking registered? You can try double clicking the button, should give you the default btn_click event handler in code behind. Also, make ...

How do I set the visibility property on a control in a user control from the host web page?
I have a user control with a few web controls like text boxes.  I want to show or hide one of the text boxes on the user control based on a variable posted to the page hosting the user control.  There may be multiple instances of the user control but they will all behave the same.  In the code behind, how do i set the text box on the user control to visible = "false" or visible = "true"?  Please provide an example as well as an explanation.Thanks! Set it from the web form by using a public property exposed on the user control. See An Extensive E...

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

Access a Web User Control Method from a Web Form
I'm trying to pass the Selected Index value from a web user control in a web form to the user controls selectedIndexchanged Sub.  I can't seem to figure out how to pass the information that I need to the user control and have it execute the sub routine. In the SelectedInedxChanged Sub I have a switch Statement and I want to get the index value from the web form where the user control is located and compare it to each case and then to have it execute the code for the case that it matches. What do I need to do? Hi, I am not sure if I understood your question correctly. I su...

Access SqlDataSource on Web Form from a Web User Control...
Hello, I want to access a SqlDataSource on a Web Form fromout. a Web User Control. To do this, I have in my code behind of the Web User Control the folowing code: DropDownList1.DataSource = (this.Page.FindControl("SqlDataSource3") as SqlDataSource);DropDownList1.DataTextField = "Name;DropDownList1.DataValueField = "NameIDropDownList1.DataBind(); But, the control (ic. SqlDataSource3) is not found. Even other controls like labels and buttons are not found with the FindControl. What am I doing wrong? Thanks Andromedaris     This is not much of a surprise,...

Interaction between Web User Control & Web form
Ok, I want to create my first Web User Control which is used for file uploading. It's very simple, consist only of the <asp:FileUpload> and <asp:Button> control. The button has one server side event which is resizing the uploaded image to two different images (stored as byte[] in the cs file). So, my question is how I can send these two arrays of type byte to the Web form where the web user control is inside. I thought it should be possible to write something like this in the Web form:<uc1:FileUploader ID="uploader" runat="server" OnUploaded="recieveImages" />So that means ...

Web resources about - How to set web user control property from client side ? -

Property - Wikipedia, the free encyclopedia
This article may require copy editing for grammar, style, cohesion, tone, or spelling . You can assist by editing it . In abstract, property ...

Property - Wikipedia, the free encyclopedia
In abstraction, property is that which belongs to or with something, whether as an attribute or as a component of said thing. For the significant ...

Thousands of dollars of property stolen from Port Augusta home during Christmas break-in - AdelaideNow ...
DEFENCE medals and unique jewellery are among thousands of dollars of property stolen during a break-in at a Port Augusta home over Christmas. ...

Facebook's Mark Zuckerberg faces trial over Silicon Valley property deal
... broke a promise to introduce him to Silicon Valley's elite. Facebook boss Mark Zuckerberg is headed toward a trial after all as the property ...

Canberra's rental yields on the rise, despite sluggish property market
Canberra has experienced the lowest annual shift in rental prices in Australia over the past decade.

Mount Isa Police crackdown nets 20 people over property theft - The Courier-Mail Search Search
ABOUT 20 people have been charged, including 17 juveniles, after a series of break and enters and thefts in Mount Isa.

Warning of 'unfair' process unheeded as government forges ahead with property resumptions
Private property is being forcibly resumed by the NSW government for major infrastructure projects such as WestConnex using a system it was warned ...

Property damage, power out in Waroona fire
At least one old property has been destroyed by intense fires that hit Waroona and Preston Beach. Vision courtesy of 9 News Perth.

Spiking property assessments may leave thousands without Home Owner Grant
A spike in property assessments in Metro Vancouver means thousands no longer qualify for the Home Owner Grant, unless the provincial government ...

Prestige property leads house price falls
Sydney property prices fell for the second consecutive month and the top end fell fastest, dropping 2.3 per cent in December, the CoreLogic RP ...

Resources last updated: 1/17/2016 9:25:19 AM