Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing a checkbox in an ascx 1

Status
Not open for further replies.

NuJoizey

MIS
Aug 16, 2006
450
US
I designed a custom control that combines a calendar control, a textbox, and a checkbox control called myCalendar.ascx.

I want to capture whether or not this checkbox is checked or not and pass it as a boolean (or bit?) to a stored procedure which returns results based on it.

I am successfully passing the value of my textbox control called txtToDate by using
Code:
<asp:ControlParameter ControlID="cphMenu3[COLOR=red]$calDatePicker$txtToDate" [/color]Name="ExpDate" PropertyName="Text" Type="DateTime" DefaultValue="cphMenu3$calDatePicker$txtToDate"  />

in other words, txtToDate lives on a my custom control object called $calDatePicker that lives in myCalendar.ascx, which in turn is sitting on my aspx page

But this does not seem to work with the checkbox.

I have no idea how to refer to my checkbox called chkApply and pass the value to my sproc as a paramter

I tried $calDatePicker$chkApply.checked in the aspx, but that didn't work. I also noodled around on the server side with Page.FindControl("chkApply") to no avail.

I'm totally stuck! What am I missing?
 
while i understand this in concept, I haven't been able to find a code example that makes sense to me when it comes to actually doing this. Can anybody point me towards a resource?
 
ok, well i figured out that this is the format to do a property - I put this in my ascx codebehind within the Partial Class delcaration:
Code:
    Public Property myProperty() As String

        Get            
            Return Me.chkApply.Checked
        End Get

        Set(ByVal Value As String)
            Me.chkApply.Checked = Value
        End Set

    End Property
You have to have the Get and the Set Statement for it to work.

Then in the aspx file it shows up in my intellisense as a property for my calendar control, and then I can do this
Code:
Response.Write(Me.calFromDate.myProperty.ToString)

apparently, this is common knowledge, and I guess that's why I had trouble finding it, because nobody seems to ask this question.

So I leave this post for all the struggling dummies out there like me, if there are any.
 
thanks ca8. The help files are helpful if you know what the common or official termininology about what you are trying to accomplish. Being still a relative newbie to .NET, i didn't even know that what I needed was to "create a public property that exposed the values of the embedded controls" Once you pointed me on that path, I could search using those phrases, but still, it seemed to take me an inordinate amount of time to find really simple basic example. You see that what I needed was quite simple, but finding it wasn't! ARRGH!
 
I understand. However, I just found the link to that particular article by searching for "ASP.NET User Control" in google and it was the first hit. Usually though, I just start at and have a search there.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
i must be exceptionally bad at goolging. not good for a programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top