Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ascx page ddl control causing postback in holder 2

Status
Not open for further replies.

tekkerguy

Programmer
Nov 16, 2005
196
US
I have an aspx page that contains a pulldown, which, when an item is selected, it adds another control to a panel on the page.

This new panel contains 2 dropdowns. When an item from dropdown1 is selected, it causes ddl2 to repopulate with a filtered list (from a sql db).

The problem is, when ddl1 is selected, it's causing the main page to do a postback, which is checking for a postback, which clears the panel.

How do I get only the control to do a postback?
 
if you dynamically add a control to a page, it must be added evertime during the Init event.
event with the MS AJAX UpdatePanel you need to add all the controls and alter the visibility property as to whether it should display on screen.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Not if you use the UpdatePanel (as this causes the full page to postback), but a true AJAX implemented method that simply returns the filtered list of values would.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Can you use ajax to execute a c# method without using updatepanel?
 
Does anyone have a link to an example that shows how to execute a c# method without using updatepanel?
 
Does anyone have a link to an example that shows how to execute a c# method without using updatepanel?
it's not so much directly executing c# w/out an update panel. it's using AJAX (asynchronis javascript and xml) to make a request to the server.

1st you need an ajax library. MS AJAX, jquery, prototype are just a few js libararies that have ajax functionality.
Then you need a page/handler/service to contact. WebServices (asmx) are the most common, although you could set it to be a starndard webform(aspx) or httphandler.
From this point it's straight forward programming on the server side to get the data.
Finally you need to present the data to the user. This can be done 1 of 2 ways. Format the data on the server and send the final output back to the client. Or, send the data only to the client and have the client build the DOM.

if you want to dynamically add dropdowns to the page using ajax and then use a postback to the final page to save changes; you must disable page validation (not data validation). This can be done through an attribute in the page directive.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
asp.net
On this page there are links to add AJAX and many intuitive videos to get you started.

To go where no programmer has gone before.
 
Ok, with the help of that page, I have my code firing javascript, which in turn fires a c# code. This code is returning a dataset, but, how do I return that dataset from the c# codebehind, to the javascript page.

I'm not "great" at javascript. I declared a var called retPulldown, which fires the cs function. I'ved stepped through the code to know that the c# method is working, but when it goes back to the javascript, the var is still set to none.

basically this is the javascript code:

Code:
function manufChanged(model, selectedIndex) 
{
   

    var modelsDS;
   modelsDS = PageMethods.ajaxManufacturer_SelectedIndexChanged(selectedIndex.value);
   debugger;
}



And this is the c# code behind:


Code:
        [WebMethod]

         public static string ajaxManufacturer_SelectedIndexChanged(string selectedIndex)
         {
             JavaScriptSerializer serializer = new JavaScriptSerializer();
             string serializedModels;

             DataSet models;

             models = addCFDrawing.UpdateModel(selectedIndex);
             serializedModels = serializer.Serialize(models);
             return serializedModels;
         }



I just recently added the serializer part to return just a string, but it's still not returning the string.



any ideas?
 
Ok, I've got this working as well, but how do I prevent it from doing a postback?
 
I had the pulldown set to autopostback from previous code. Removed that and it's all working!

Thanks for everyone's help!.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top