locked
Web User Control Doesn't Accept it's property RRS feed

  • Question

  • User1261460523 posted
    Hi.

    I wrote a web user control. It has a calender and if you click on a date it shows you the events belongs to selected date. And also if you want to see the event you should write the password before to the textbox, otherwise you don't have access to see the events. You can see my control below:

    Control

     

     

     

     

     

     

     

     

     

     

    This user control's code behind is like this :

    public partial class ValiDateControl : System.Web.UI.UserControl
    {
        public ValiDateControl()
        {
            _Validation = false;
        }
    
        private string Date
        {
            get { return Calendar.SelectedDate.ToShortDateString(); }
        }
    
        private bool _Validation = false;
        public bool Validation
        {
            get { return _Validation; }
        }
    
        private string _Address = "";
        public string Address
        {
            get { return _Address + "?Date=" + Date; }
            set { _Address = value; }
        }
    
        protected void Calendar_SelectionChanged(object sender, EventArgs e)
        {
    
            if (PasswordText.Text == "123456")
            {
                _Validation = true;
                Response.Redirect(Address);
            }
            else
                WarningLabel.Text = "Invalid Password";
        }
    }


    When i add this control to a page i set it's address with Address property. But it never sets it's address property like this :

    protected void Page_Load(object sender, EventArgs e)
        {
            ValiDateControl vdc = new ValiDateControl();
            vdc.Address = "Events.aspx";
        }


    When i try it like above, it always set address null. So it never goes to webpage that i want. It's result in the address bar always like this : http://localhost:4533/TarihKoruma/?Date=12.05.2010 but i want it like this : http://localhost:4533/TarihKoruma/Events.aspx?Date=12.05.2010

    I hope i could explain my problem. :(

     

    Saturday, May 22, 2010 5:28 PM

Answers

  • User197322208 posted

    I mean when i set the Address property in my web user control's code behind, it works, but if i try to set it in a web page (like Default.aspx) that i add my user control as below:


    1. protected void Page_Load(object sender, EventArgs e)    
    2. {    
    3.     ValiDateControl vdc = new ValiDateControl();    
    4.     vdc.Address = "Events.aspx";    
    5. }   
    protected void Page_Load(object sender, EventArgs e)  
    {  
        ValiDateControl vdc = new ValiDateControl();  
        vdc.Address = "Events.aspx";  
    } 


    it doesn't work, it returns the Address as null.

    I think I have been not explicit

    Do you have in the aspx page(not aspx.cs) a Validate control ? What's the code?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 23, 2010 11:15 PM

All replies

  • User197322208 posted

  • protected void Page_Load(object sender, EventArgs e)  
  •     {  
  •         ValiDateControl vdc = new ValiDateControl();  
  •         vdc.Address = "Events.aspx";  
  •     } 


Do you add the vdc to the controls list or do you have on aspx page another ValiDateControl  control?

Saturday, May 22, 2010 11:41 PM
  • User1261460523 posted

    I mean when i set the Address property in my web user control's code behind, it works, but if i try to set it in a web page (like Default.aspx) that i add my user control as below:

     

    protected void Page_Load(object sender, EventArgs e)  
    {  
        ValiDateControl vdc = new ValiDateControl();  
        vdc.Address = "Events.aspx";  
    } 


    it doesn't work, it returns the Address as null.

    Sunday, May 23, 2010 11:52 AM
  • User197322208 posted

    I mean when i set the Address property in my web user control's code behind, it works, but if i try to set it in a web page (like Default.aspx) that i add my user control as below:


    1. protected void Page_Load(object sender, EventArgs e)    
    2. {    
    3.     ValiDateControl vdc = new ValiDateControl();    
    4.     vdc.Address = "Events.aspx";    
    5. }   
    protected void Page_Load(object sender, EventArgs e)  
    {  
        ValiDateControl vdc = new ValiDateControl();  
        vdc.Address = "Events.aspx";  
    } 


    it doesn't work, it returns the Address as null.

    I think I have been not explicit

    Do you have in the aspx page(not aspx.cs) a Validate control ? What's the code?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 23, 2010 11:15 PM
  • User1261460523 posted

    I solved it. I have a control in my default.aspx :) But i try to create a new object with the code. I'm sorry it's very simple fault, i stole your time. Thanks again i solved it.

    Monday, May 24, 2010 5:48 AM
  • User197322208 posted

    I have a control in my default.aspx :) But i try to create a new object with the code

    That's what I tried to tell you ...


    Monday, May 24, 2010 9:27 AM
  • User1261460523 posted

    yes. thank you again. first i couldn't undersand but then i could understand what you mean. thanks a lot.

    Monday, May 24, 2010 10:26 AM