Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
i create one user control with multiple properties like text id css.
one of them property is EventList for Calling JavaScript Function.

Issue :
Eventlist property accept only one value but i want to set multiple value seprated by semicolon and select from enum.

i want to use this like style tag in html attribute
example :
style="color: Red; background-color: White; height: 100px"
I Want
EventList="OnClick;OnBlur;OnKeyUp"

Code
C#
public enum JSFunctions
      {
          OnChange,
          OnClick,
          OnKeyUp,
          OnKeyDown,
          Onhelp,
          Onblur,
          Onfocus,
          Ondblclick,
          onmousedown,
          onmousemove,
          onmouseup,
          onmouseout,
          OnChange_OnKeyUp,
          OnChange_OnKeyDown,
          OnChange_Onblur
      }



//Property
C#
// Event for Invoking JavaScript
      private JSFunctions _jsfunction;
      public JSFunctions EventList
      {
          get { return _jsfunction; }
          set { _jsfunction = value; }

      }

//User Control
<cc1:CompositeText ID="CompositeText2" runat="server" EventList="Onblur" ErrorMessageType="MessageBox"
           OtherJSFunction="Arvind();" />
Posted
Updated 21-Dec-10 2:21am
v2
Comments
Toniyo Jackson 21-Dec-10 8:22am    
Use pre tag for code.

1 solution

What I think you want to do is set the Flags attribute on your enum list, and then add another item to it:

C#
[Flags]
public enum JSFunctions      
{
    None=0,
    OnChange=1,
    OnClick=2,
    OnKeyUp=4,
    OnKeyDown=8,
    Onhelp=16,
    Onblur=32,
    Onfocus=64,
    Ondblclick=128,
    onmousedown=256,
    onmousemove=512,
    onmouseup=1024,
    onmouseout=2048,          
    OnChange_OnKeyUp=4096,
    OnChange_OnKeyDown=8192,
    OnChange_Onblur=16384,
    All=32768
}



At that point, you can set multiple enum values to your EventList property like this:

C#
this.EventList &= (JSFunctions.OnKeyUp & JSFunctions.Onhelp);


At this point, all you have to do to set the control's EventList property is to write a method that builds a string from the flags.

C#
private string GetFlagIfSet(JSFunctions jsfuncs, JSFunction func)
{
    string flagName = "";
    if (jsfuncs != JSFunction.None)
    {
        if ((jsFuncs | func) == func)
        {
            flagName = string.Format("{0};", func.ToString());
        }
    }
    return flagName;
}


I'll leave the rest for you to fill in (and keep in mind I did this off the top of my head, so it may need some tweaking).

Go forth and code.

 
Share this answer
 
v2
Comments
Arvind Wanjari 22-Dec-10 4:13am    
thanx john ..
but my problem that server control can's accept multiple values
in Below control i want to set
EventList="Onblur;onChange"

<cc1:CompositeText ID="CompositeText2" runat="server" EventList="Onblur" ErrorMessageType="MessageBox"
OtherJSFunction="Arvind();" />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900