Solved

How to invoke a checkbox change event within code behind

Posted on 2010-11-24
8
1,123 Views
Last Modified: 2012-05-10
I have an ASP.NET page, I have a checkbox which has a checkbox change event.

How do I trigger a checkbox change event from code behind.

I tried to add this line in one of my methods to inovke the changed method
But it fails with object reference set to an instance of an object, because the value of System.Web.HttpUtility.UrlDecode(Request.Form("__EventTarget")) is Nothing



cbDetailOrder_SelectedIndexChanged(cbDetailOrder, New EventArgs())



Protected Sub cbDetailOrder_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbDetailOrder.SelectedIndexChanged

      If System.Web.HttpUtility.UrlDecode(Request.Form("__EventTarget")).EndsWith(cbDetailOrder.ID) Then
            'blah blah

      end if
End SUb
0
Comment
Question by:countrymeister
8 Comments
 
LVL 9

Accepted Solution

by:
Gorkem Yuksel earned 100 total points
ID: 34207273
Countrymeister,

In the past, I have been able to trigger the event by calling the function directly (in C#):

C#:
cbDetailOrder_SelectedIndexChanged(null, null);

in VB, I assume it would be:

cbDetailOrder_SelectedIndexChanged(nothing, nothing)

I hope this helps,

G.
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 200 total points
ID: 34207321
Maybe you should start at the beginning and explain what it is you are trying to achieve. You can't trigger a client-side event from server code, like you are doing, if you need context information from the Form.
0
 
LVL 1

Author Comment

by:countrymeister
ID: 34207674
gyuksel:
If I do the following
cbDetailOrder_SelectedIndexChanged(nothing, nothing)

as I already mentioned it fails
because the EVENTTARGET is empty
0
 
LVL 1

Author Comment

by:countrymeister
ID: 34207706
carl_tawn:
I need to invoke the checkbox changed event, not sure if I can use Page,RegisterClientScript or somehow get the document checkbox changed event.

I have a link on a another page, which uses the query string to pass the order id. and on getting the order id I want to use cb_changed event to load the details of the orderid passed
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 200 total points
ID: 34207746
So, your checkbox is on the page targetted by the link? and that link passes an order id in the querystring? If that IS the case, then can't you just take the order id from the querystring rather than trying to invoke the checkbox event?

And what goes in the "blah, blah" section? Depending on what the is doing you could strip it out into it's own method and call it directly, thus avoiding all the _EVENTTARGET stuff.
0
 
LVL 7

Assisted Solution

by:meispisces
meispisces earned 100 total points
ID: 34208077
Instead of cbDetailOrder_SelectedIndexChanged(nothing, nothing) try cbDetailOrder_SelectedIndexChanged(null, null)
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 100 total points
ID: 34208145
I handle these scenarios by moving all the code to a separate function which is then called by the event handler as well as any other code which needs to execute it.

So

Private Sub cbDetailOrder_SelectedIndexChanged(...)
     LoadDetails()
End Sub

Private Sub LoadDetails()
'all the code here
End Sub

0
 
LVL 1

Author Closing Comment

by:countrymeister
ID: 34263379
I don't think any one of them answered my question
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now