?
Solved

How to invoke a checkbox change event within code behind

Posted on 2010-11-24
8
Medium Priority
?
1,151 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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

764 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