Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to invoke a checkbox change event within code behind

Posted on 2010-11-24
8
Medium Priority
?
1,159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 9

Accepted Solution

by:
Gorkem Yuksel earned 200 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 400 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 400 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 200 total points
ID: 34208077
Instead of cbDetailOrder_SelectedIndexChanged(nothing, nothing) try cbDetailOrder_SelectedIndexChanged(null, null)
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 200 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…
Suggested Courses

618 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