darren166
Posts: 24
|
Posted: 09/20/2005, 12:41 PM |
|
Hi, I'm developing a site with c# and have a simple search control and results grid. All is working fine and to search you use a dropdown list to select the value then click the submit button.
I wanted to make it a little more automated and attached an action to the client 'onChange' event using codecharge studio so that the form is submitted when the select box value changes. All the code is generated, but nothing happens when I use the listbox.
I tried making it more simple so that a message box is displayed 'onchange' but that doesn't work either. I know I have got this working with asp, but this is the first time I have tried it with asp.net. Is there anything preventing me being able to do this with an asp.net project??
Thanks.
Darren.
_________________
---
a. w. d. - c o n s u l t i n g
Midnight Oil Consumers. |
|
|
E43509
Posts: 283
|
Posted: 09/20/2005, 6:05 PM |
|
I done it in VB and I'm sure you can noodle out how to make this done in C#. You can find some of the components naming by looking at the actual aspx file that CCS generates. You need to cause the form to post back.
In the before show event, you need to add javascript programmatically.
MyFormSearchsButton.Attributes("OnChange") = "javascript:__doPostBack('MyFormSearchButton_DoSearch','')"
|
|
|
darren166
Posts: 24
|
Posted: 09/21/2005, 4:02 AM |
|
Thanks for that it was very helpful!
For anyone interested I used the following in the before show event;
View_CMS_PageListSearchs_Role.Attributes["OnChange"] = "javascript:__doPostBack('MainContent:_ctl0:View_CMS_PageListSearchButton_DoSearch','')";
Where View_CMS_PageListSearchs_Role is the name of my dropdown list and is obtained by looking at the generated code for the aspx page within codecharge, and 'MainContent:_ctl0:View_CMS_PageListSearchButton_DoSearch' is the id of my search button obtained by looking at the code for the actual aspx page generated within your browser.
I am happy that it is working, however I still don't understand why this doesn't work by assigning an action to the onChange event within codecharge itself. Is this a bug??
Darren
_________________
---
a. w. d. - c o n s u l t i n g
Midnight Oil Consumers. |
|
|
paulray
|
Posted: 09/28/2005, 8:44 AM |
|
Tried your solution and I can't get it to work.
I noticed that when I select from the listbox, the url reads; http://localhost/RateRules/listRateApp.aspx
Yet when I click the Search button, the url reads; http://localhost/RateRules/listRateApp.aspx?s_Client_ID=NSG
Here's my code...
tblARApplicationSearchs_Client_ID.Attributes("OnChange") = "javascript:__doPostBack('tblARApplicationSearchButton_DoSearch','')"
tblARApplicationSearchs_Client_ID is the listbox
tblARApplicationSearchButton_DoSearch is the search button.
This is in the BeforeShow event of the form
Any ideas? Thanks
|
|
|
darren166
Posts: 24
|
Posted: 09/28/2005, 9:27 AM |
|
Are you getting the id of your search button from the aspx page as seen in the browser (rather than within codecharge)? Open your app in the browser and go to the page that has the search form, then view the source of that page and get the search button id from there.
Darren
_________________
---
a. w. d. - c o n s u l t i n g
Midnight Oil Consumers. |
|
|
paulray
|
Posted: 09/28/2005, 10:17 AM |
|
Thanks Darren, it works. Seems my browser cache was getting in the way until I cleared it. Had all proper stuff all along. Wouldn't have realized it had I not looked at the source.
Paul
|
|
|
jeden
Posts: 20
|
Posted: 11/17/2005, 11:53 PM |
|
Quote paulray:
Thanks Darren, it works. Seems my browser cache was getting in the way until I cleared it. Had all proper stuff all along. Wouldn't have realized it had I not looked at the source.
Paul
Hi,
the info I found in this thread were very useful in order to solve the same problem.
Anyway, instead of wasting time searching for the actual id of the control, I'd rather use the ClientID property (exposed by any control derived from System.Web.UI.Control) as follows:
TimeTableSearchProjectId.Attributes ["OnChange"] = string.Format ("javascript:__doPostBack ('{0}')", TimeTableSearchButton_DoSearch.ClientID);
This way you don't have to search for the actual ID of the control inside the generated html code.
Hope this hint helps :)
Antonio
_________________
Antonio Bello
Elapsus - Software & Solutions
http://www.elapsus.com
Developer's Corner
http://www.developer-corner.com |
|
|
jeden
Posts: 20
|
Posted: 11/18/2005, 12:39 AM |
|
I've just found another better way:
TimeTableSearchs_ProjectId.Attributes ["OnChange"] = string.Format ("javascript:{0}", Page.GetPostBackEventReference(TimeTableSearchButton_DoSearch));
Simpler, isn't it? No need to deal with client ids and js functions :)
Antonio
_________________
Antonio Bello
Elapsus - Software & Solutions
http://www.elapsus.com
Developer's Corner
http://www.developer-corner.com |
|
|
Abs
|
Posted: 12/15/2005, 4:19 AM |
|
Hi,
Thanks for this. Can this also be done for onclick event for radio buttons?
Abs
|
|
|
Abs
|
Posted: 12/15/2005, 4:26 AM |
|
Don't worry, I just tried it by changing the onChange to onClick, and it does work... great.
Thanks
|
|
|
nitin
|
Posted: 01/02/2006, 10:19 PM |
|
how to show onchange event on<select> so that we r geting the another <select> contains the sub list .plz send the source code with jsp
|
|
|
Steve Anderson
|
Posted: 03/17/2006, 2:10 AM |
|
How can we do a Onchange event for a DropDownList in client side and server side at the same time.
|
|
|