Solved

How to invoke a checkbox change event within code behind

Posted on 2010-11-24
8
1,139 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 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult 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…

724 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