Search:
Namespaces
Discussions
.NET v1.1
Feedback
CheckBox CheckChanged EventHandler not working?
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.languages.csharp
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...
R Reyes (VIP)
I have a login page with two checkboxes, one for automatic login and the
other for remember username. When automatic login is checked, I simply want
the remember username checkbox to be checked too, but the eventhandler is
NEVER executed. do i need to create a different type of event handler?
Here is my code:
CheckBox
cb = new
CheckBox
();
cb.ID = "myCheckBox";
cb.Text = "Remember Username";
cb.CheckedChanged += new System.
EventHandler
(this.cb_CheckedChanged);
// this is never executed
private void cb_CheckedChanged(object sender,
EventArgs
e) {
Response.Write ("WE ARE HERE...AWESOME!!!!");
cbUserNameRemember.Checked = true;
}
please help. thanks in advance.
Reply to this message...
Trebek
You have to set the 'AutoPostBack' property to true in order to have your
event fire. Of course, this will cause a post back so you might wanna think
about client-side script instead if you expect high traffic.
HTH,
Alex
"R Reyes" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
R Reyes (VIP)
Oh really? That stinks. I'm not expecting high traffic but I didn't realize
you had to have a page submit for a function as easy as this to work. Ugh, I
was hoping I wouldn't need to have any client side scripting. I didn't
really want to use javascript/vbscript. I like handling everything in
c#...at least ever since i've converted. And I guess it was assuming too
much that an event handler would be able to change stuff on a webform w/o the
need to submit. But...I guess that does make sense.
Thanks Trebek. And if anyone has any other ideas besides client-side
scripting, I'm all ears.
"Trebek" wrote:
[Original message clipped]
Reply to this message...
Marina
I am assuming this is in asp.net, in which case you should post to the
asp.net newsgroup in the future.
You have to recreate the checkbox and reattach the event handler on
postback.
"R Reyes" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
R Reyes (VIP)
it is an asp.net control, but i am coding the server-side .dll in c#. in
fact, i hardly use any asp code in my website at all. mostly all code is
done in c# which is why i need the c# solution, not the asp.net solution.
"Marina" wrote:
[Original message clipped]
Reply to this message...
Marina
ASP.NET is the term for web application - C# is just one language such an
application can be coded in. So an 'ASP.NET solution' is a term that has no
meaning, since all solutions will involve a .NET language.
"R Reyes" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
R Reyes (VIP)
"You have to recreate the checkbox and reattach the event handler on postback."
Not sure if I'm understanding how PostBack or recreation works in regard to
my problem. I thought PostBacks only happen when a page is submitted. I
might be wrong, but anyway I am not submitting the page. It is just suppose
to be a CheckChanged event that waits for the user to click the checkbox and
then when clicked, changes the true/false value of another checkbox. Where
does PostBack or recreation come into play if the page is not being submitted
anywhere? This is something that could handled with javascript too but
again, I am looking for how to do this in C# code.
FYI, I've reposted this in the ASP.NET forums and hopefully someone will
have a reply there as well.
"Marina" wrote:
[Original message clipped]
Reply to this message...
R Reyes (VIP)
Take a look at Trebek's response. Is that what you meant by PostBack and
recreation? Either way I was guessing from his response that I would have to
use client side scripting since a Postback has to occur (which I don't really
want).
I guess I will have to client side script it though unless you had another
workaround which you were trying to explain to me that I didn't understand
from your previous post.
"R Reyes" wrote:
[Original message clipped]
Reply to this message...
Marina
If you want an event to fire on the server - then the page has to make a
request to the server. Otherwise how could it possibly happen, with the page
sitting on the client and the server being elsewhere and completely
disconnected?
The page posting to the server, is what can trigger an event - in this case
you want the CheckChanged event.
If the page is not being submitted, then I don't see how you can expect a
server side event to run.
If you want a client side event to run - then i don't see how you can expect
to have C# code execute in response to it - since that is code that would
have to run on the server - but you don't want the page going to the server.
In the end, you have to have some javascript on the page, since that is the
only way to get client side event handling.
"R Reyes" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
> "You have to recreate the checkbox and reattach the event handler on
postback."
[Original message clipped]
Reply to this message...
R Reyes (VIP)
Got it, thanks.
"Marina" wrote:
[Original message clipped]
Reply to this message...
System.EventArgs
System.EventHandler
System.Web.UI.WebControls.CheckBox
System.Windows.Forms.CheckBox
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com