Dynamic Property changing for usercontrol

Posted by Community Admin on 03-Aug-2018 09:54

Dynamic Property changing for usercontrol

All Replies

Posted by Community Admin on 31-Aug-2011 00:00

Hi,

i want to create the dropdown control dynamically for usercontrol properties and assigned all news to the dropdown list.
if i am select the value of the dropdown its show the  particular news item in my usercontrol.


public class NewsSelector : WebUITypeEditor<string>

    private DropDownList NewsDDL = null;
    private string _Value = null;
public NewsSelector()

//
// TODO: Add constructor logic here
//

    public override string Value
   
        get return _Value;
        set _Value = value;
   
    protected override void CreateChildControls()
   
        Controls.Clear();
        Controls.Add(new LiteralControl("Select Language: "));
       NewsDDL = new DropDownList();
       NewsDDL .Style.Add("Width", "350px");
        NewsDDL.SelectedIndexChanged += new System.EventHandler(NewsDDL_SelectIndexChanged);




        DataTable dtNews = DBLib.ExecuteSQLReturnDataTable("Usp_GetAllNews");
        if (dtNews .Rows.Count > 0)
       
              NewsDDL.DataSource = dtLanguage;
             NewsDDL.DataTextField = "News";
             NewsDDL.DataValueField = "NewsId";
             NewsDDL.DataBind();
       


        //NewsDDL.Items.Insert(0, new ListItem("Select", "0"));
        Controls.Add(NewsDDL);


        if (NewsDDL.Items.Count > 0)
            Value = NewsDDL.SelectedItem.Value;
   


    void NewsDDL_SelectIndexChanged(object sender, System.EventArgs e)
   
        Value =NewsDDL.SelectedValue;


   



its working in sitefinity 3.7 but i need in 4.2 plz give solution for that.here  WebUITypeEditor<string>  didnt work.

Posted by Community Admin on 02-Sep-2011 00:00

Hi Mari,

Sitefinity 4.x API model is very different from 3.7. Instead of WebUITypeEditor<string> you should use SimpleView. Please check the following blog posts that outline how to create a custom widget for Sitefinity 4.x

http://www.sitefinity.com/blogs/joshmorales/posts/11-09-01/anatomy_of_a_sitefinity_4_widget.aspx

http://www.sitefinity.com/blogs/ivan/posts/11-01-18/implementing_sitefinity_widgets_and_designers_how_to_implement_facebook_like_button.aspx

Greetings,
Lubomir Velkov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Posted by Community Admin on 05-Sep-2011 00:00

Thanks for kindly help.

in this case used the textbox value to bind,(in jquery)
but i want dropdown list for bind

i used like this way ,
Type.registerNamespace("sitefinity42.Widgets.HelloWorld");


sitefinity42.Widgets.HelloWorldDesigner = function (element)
    sitefinity42.Widgets.HelloWorldDesigner.initializeBase(this, [element]);



sitefinity42.Widgets.HelloWorldDesigner.prototype =
    initialize: function ()
        sitefinity42.Widgets.HelloWorldDesigner.callBaseMethod(this, 'initialize');
    ,
    dispose: function ()
        sitefinity42.Widgets.HelloWorldDesigner.callBaseMethod(this, 'dispose');
    ,
    refreshUI: function ()
        var controlData = this._propertyEditor.get_control();


        // bind widget properites to designer
        jQuery("#txtName").val(controlData.Name);
       // jQuery("#DropDownList1 option:selected").Text(controlData.Name2);




    ,
    applyChanges: function ()


        var controlData = this._propertyEditor.get_control();


        // bind designer properties back to widget
        controlData.Name = jQuery("#txtName").val();
        //controlData.Name2 = jQuery("#DropDownList1 option:selected").Text();


   



sitefinity42.Widgets.HelloWorldDesigner.registerClass('sitefinity42.Widgets.HelloWorldDesigner', Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesignerBase);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();



but its not helped,

plz help me out from that.

thanks and regards,
Mari

Posted by Community Admin on 08-Sep-2011 00:00

Hi Mari,

Could you send us the whole code that you have - the .cs designer, any .ascx template and the Javascript. Having this piece of Javascript code out of context isn't helping much.

Regards,
Lubomir Velkov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

This thread is closed