Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET jQuery Events
I've created a usercontrol which has a calender control having only months displayed i.e in JAN,FEB,etc !! This user control calender is toggled from parent page's textbox(using Jquery),my code is fine till here.
 
Now what I want is to display those calender value in numeric form ;to achieve this I've declared an enum i.e
 
enum monthsOfYear 
{ 
    Jan = 1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec 
};
 
int x = (int)monthsOfYear.Jan;//x=1 here and this value will be passed to textbox of
                               //other page(.aspx)
 
Now as all the months has its value assigned (in the code behind of user calender.ascx page),these respective values I want to pass on to the textbox of parent page (where this calender is toggled) on an individual click of any of the above months(month link button in user control).
As I'm getting the value in "x" in my .ascx page ,but this values I want to pass into 3 textboxes of my parent.aspx page.
 
I've also tried using delegates but still not got the result.Because, the event is fired on the link button of user control page and after this event the value(from text of linkbutton) must be passed to the aspx page textboxes.
 
If any clarification then let me know.
please help me in achieving this task.
Thanks in advance !!
Posted 15-Apr-13 21:46pm
Rabbil1.5K
Edited 16-Apr-13 0:31am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try defining property to access variable that is in user control.
 
For ex:

UserControl.ascx:
enum monthsOfYear 
{ 
    Jan = 1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec 
};
 
int x = (int)monthsOfYear.Jan;
public int MonthName
{
   get { return x; }
}
 
 
Page.aspx:
 
TextBox1.text = UserControl.MonthName;
  Permalink  
Comments
Rabbil at 16-Apr-13 5:28am
   
Thank you for your response...!!
I've defined the property but in the aspx page that textbox is not acessing the UserControl.MonthName.... what to do ?
Vani Kulkarni at 16-Apr-13 5:31am
   
Would you please post the code?
Rabbil at 16-Apr-13 5:47am
   
I've used one textbox in .ascx just to check whether GetValue() Property defined is working fine or not and this is supported by Jquery using css class...
Any more clarification ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Below UC I'm using in my .aspx page
 
<asp:textbox id="txtMonths" runat="server" cssclass="controlMonYr" xmlns:asp="#unknown"></asp:textbox> //here i want to pass the selected value from user control
  <cc:calenderctrl id="ccd"  runat="server" getvalue="txtMonths" xmlns:cc="#unknown"></cc:calenderctrl>//getvalue is property defined in .ascx page, below is the defination
 
In userControl.ascx page  
 
<pre lang="HTML">  <td>
                        <asp:TextBox ID="txtB" runat="server"></asp:TextBox> //this textbox is getting filled with string value on cell1_click
                    </td>
 
Below tag is a single tag,like this till cell12
<pre>
<td>
       <asp:LinkButton ID="Cell1" runat="server" OnClick="Cell1_Click"></asp:LinkButton>
</td>

 
public int MonthName
    {
        get { return x; }
    }
 
    private string _getValue;
 
    /// <summary>
    /// To access the value from usercontrol and pass on to the textbox in usercontrol itself
    /// </summary>
    public string GetValue
    {
        get { return _getValue; }
        set { _getValue = value; }
    } 
 
 protected void Cell1_Click(object sender, EventArgs e)
    {
        LinkButton senderId = (LinkButton)sender;
        int passValue=1;
        if (!int.TryParse(senderId.Text.ToString(), out passValue))
        {
            GetValue = senderId.Text.ToString();
            txtB.Text = GetValue;
        }
        if(int.TryParse(senderId.Text.ToString(), out passValue))
        {
            lnkYear.Text = senderId.Text.ToString();
            DateTime passDate = DateTime.Parse("01-01-" + senderId.Text.ToString());
            CellValues(passDate, "M");            
        }   
        
    }
 
 private void CellValues(DateTime paramDate, string operation) ///In paqe load of .ascx it called
    {
        if (operation == "M")
        {            
            lnkLstYear.Visible = false;
            ltrHyp.Text = "";
            Cell1.Text = "Jan";
            Cell2.Text = "Feb";
            Cell3.Text = "Mar";
            Cell4.Text = "Apr";
            Cell5.Text = "May";
            Cell6.Text = "Jun";
            Cell7.Text = "Jul";
            Cell8.Text = "Aug";
            Cell9.Text = "Sep";
            Cell10.Text = "Oct";
            Cell11.Text = "Nov";
            Cell12.Text = "Dec";           
        }
        else
        {
            lnkLstYear.Visible = true;
            int providedYear = Convert.ToInt32(lnkYear.Text.ToString());
            Cell1.Text = providedYear.ToString() ;
            Cell2.Text = (providedYear + 1).ToString();
            Cell3.Text = (providedYear + 2).ToString();
            Cell4.Text = (providedYear + 3).ToString();
            Cell5.Text = (providedYear + 4).ToString();
            Cell6.Text = (providedYear + 5).ToString();
            Cell7.Text = (providedYear + 6).ToString();
            Cell8.Text = (providedYear + 7).ToString();
            Cell9.Text = (providedYear + 8).ToString();
            Cell10.Text = (providedYear + 9).ToString();
            Cell11.Text = (providedYear + 10).ToString();
            Cell12.Text = (providedYear + 11).ToString();
            lnkLstYear.Text = Cell12.Text;
            ltrHyp.Text = "-";
        }
    }
 
Should I place the JQuery or my usercontrol in more detail...?? if this much is not enough ?
  Permalink  
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Did you register user control with the web page??
 
Do like this :-
 
1. first create user control
2. create property that return MonthName
 
public int MonthName
{
   get{return DateTime.Now.Month;}
}
 
3.Now create web Page(.aspx) and register user control.
<![CDATA[<%@ Register Src="~/WebUserControl1.ascx" TagName="UC" TagPrefix="UC" %>
 
4. Now create Text box and submit button in aspx page.
 
 <UC:UC ID="userControl1"  runat="server" />
<asp:Button ID="btnInsert" runat="server" onclick="btnInsert_Click" Text="Submit" />
 <br />
 <asp:TextBox ID="txtMonth" runat="server"></asp:TextBox>
 
5. Now on click of button or on page load you can set MonthName in textbox.
protected void btnInsert_Click(object sender, EventArgs e)
        {
           txtMonth.Text=userControl1.MonthName.ToString();
        }
 
6. Done
  Permalink  
v2
Comments
Rabbil at 16-Apr-13 9:58am
   
Thank you for your valuable response....
Yeah,I've registered UserControl....
upto step 5 I've done (according to your above code) but after this what I want is how to pass the respective values i.e if Jan=1 then 1 must be displayed in the textbox after onclick event of the text from UC,rather I'm getting JAN displayed into the textbox.Also, I'm not supposed to use btnInsert.So which event will be fired to get this result ?
Or should I display JAN in the txtMonth textbox and rather convert its value from the code behind so that its value (i.e value of JAN=1 ) will only be sent to DB and not JAN... ??

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 230
2 BillWoodruff 205
3 DamithSL 165
4 Sergey Alexandrovich Kryukov 155
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100