Solved

How to invoke a checkbox change event within code behind

Posted on 2010-11-24
8
1,132 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

808 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