Forum
 
 
Knowledge Base Forum
To post messages on the forum, you need to login first.
SearchForum Home
  Product Forums  smartDBforms.NET  Autopostback on...
 Autopostback on Dropdowns
 
 2/13/2011 3:59:30 PM
Brett
6 posts


Autopostback on Dropdowns
Found it easy enough to modify the template.ascx to create autopostback=true on dropdown boxes. However, seems a bit kludgy trying to trap the postback and determine the control that caused the postback AND get the value of the dropdown. What I really want to do, based upon the dropdown selected, make some other smartdb controls visible or not visible. Any examples or suggestions? Thanks!
 2/15/2011 4:42:31 AM
Adillis Support
51 posts
adillis.com


Re: Autopostback on Dropdowns
Hi Brett,

You can achieve auto post back by dynamically setting the AutoPostBack property of the dropdown and dynamically registering
for the
SelectedIndexChanged event.
SelectedIndexChanged is fired when the user has selected a new item in the dropdownlist.

Using this technique, there will be no need to modify the TemplatesStorage.ascx file.

The AutopostBack property is changed when the DropDownList is created this is the event
SmartDBControl.ondatabinding.

The SelectedIndexChanged is registered each time the SmartDBControl is loaded.
This is
SmartDBControl.onload event.

Below is example for the CategoryID dropdown.

ctrlCategoryID_DataBinding
method changes the AutoPostBack property.
ctrlCategoryID_Load registers the dropDownValue_SelectedIndexChanged event handler.
In the dropDownValue_SelectedIndexChanged method you put the code that should be executed when the dropdown selection changes.

You can download the full aspx page from here:
AutoPostBackProducts.zip
...
<
smartDBforms:SmartDBControl Field="CategoryID" ID="ctrlCategoryID"
runat="server"
onload
="ctrlCategoryID_Load"
ondatabinding="ctrlCategoryID_DataBinding"
...
/////////////////////////////////

// DROPDOWN AUTOPOSTBACK EXAMPLE
protected void ctrlCategoryID_Load(object sender, EventArgs e)
{
// On page load register for the SelectedIndexChanged event which
//will fire when the user has changed the drop down selection.

DropDownList dropDownValue = ((SmartDBControl)sender).FindControl("DropDownValue") as DropDownList;
// Dropdown is availailable only in Edit mode. Check if exist.
if (dropDownValue != null)
dropDownValue.SelectedIndexChanged += new EventHandler(dropDownValue_SelectedIndexChanged);
}
protected void ctrlCategoryID_DataBinding(object sender, EventArgs e)
{
// When dropdown is created set its Autopostback to true.
DropDownList dropDownValue = ((SmartDBControl)sender).FindControl("DropDownValue") as DropDownList;
// Dropdown is availailable only in Edit mode. Check if exist.
if (dropDownValue != null)
dropDownValue.AutoPostBack = true;
}
void dropDownValue_SelectedIndexChanged(object sender, EventArgs e)
{
//TODO: Do something.
Page.Title +=" Selected Category value is:"+ ((DropDownList)sender).SelectedValue;
}


If you have any other questions, we will be more than happy to help you.
Best wishes,
Adillis Support
Adillis - IT solutions http://adillis.com

 2/23/2011 10:19:58 AM
Adillis Support
51 posts
adillis.com


Re: Autopostback on Dropdowns
Hi Brett,

A new feature will be added to the next release of smartDBforms.NET
which will allow to easily achieve the AutoPostBack functionality.

Here is description of the future feature:

SmartDBControl will have custom property AutoPostBack
which will enable the AutoPostBack of the underlying DropDownList.
SmartDBControl will have CustomEvent "SelectedIndexChanged"
which will fire when the underlying DropDownList.SelectedIndexChanged fires.
This will allow to achieve the AutoPostBack functionality with minimum code
.

If you have any other questions, we will be more than happy to help you.
Best wishes,
Adillis Support
Adillis - IT solutions http://adillis.com
  Product Forums  smartDBforms.NET  Autopostback on...
Copyright 2006-2012 Adillis Terms Of Use Feedback Contact Us