i put 2 Dropdownlist inside a updatepanel. whenever 1st dropdownlist selected index changes 2nd dropdownlist's item changes.(like Country-State.. here in my case its city-area).
Whenever i change 1st dropdownlist(DDLCity1) selectedindex no problem, it works fine. But Two times only.
suppose, after page load i select "LA" no problem, area of LA will load in another dropdownlist DDLArea1. then i nake change, select "NY" city, again another dropdownlist will works fine.
BUT NOW ON THERD ATTEMPT MY 2ND DROPDOWNLIST SHOW NO CHANGES!!!!! IT sTILL SHOW LAST RESULT.
IN SORT, postback works only 2 times.
for testing i put a alert msg on indexchange of dropdown it popups only 2 times. seems like postback only 2 times :(( plzz help me;
<pre>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ViewStateMode="Enabled" UpdateMode="Always">
<ContentTemplate>
<asp:DropDownList ID="DDLCity1" runat="server" AutoPostBack="false" OnSelectedIndexChanged="DDLCity_SelectedIndexChanged"
ViewStateMode="Enabled">
<asp:ListItem Text="- All City -" />
</asp:DropDownList>
<asp:DropDownList ID="DDLArea1" runat="server" Style="margin-bottom: 0px" OnSelectedIndexChanged="DDLArea_SelectedIndexChanged"
AutoPostBack="false" ViewStateMode="Enabled">
<asp:ListItem Text="- Anywhere -" />
</asp:DropDownList>
<span style="position: absolute;">
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<img src="img/loading.gif" alt="Alternate Text" />
</ProgressTemplate>
</asp:UpdateProgress>
</span>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DDLCity1" EventName="SelectedIndexChanged" />
</Triggers>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DDLArea1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<code>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DDLCity1.DataSource = objsql.GetTable("select distinct city from tblCity where status=1 order by city");
DDLCity1.DataTextField = "city";
DDLCity1.DataValueField = "city";
DDLCity1.DataBind();
DDLCity1.Items.Insert(0, new ListItem("- All India -", "- All India -"));
if (Request.Cookies["ddCityCookie"] != null)
{
ddlCity.SelectedIndex = int.Parse(Request.Cookies["ddCityCookie"].Value);
if (Request.Cookies["ddAreaCookie"] != null)
{
ddlArea.SelectedIndex = int.Parse(Request.Cookies["ddAreaCookie"].Value);
}
}
}
protected void DDLCity_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownCityIndexChange();
DDLArea1.SelectedIndex = 0;
}
protected void DDLArea_SelectedIndexChanged(object sender, EventArgs e)
{
HttpCookie ddAreaCookie = new HttpCookie("ddAreaCookie");
ddAreaCookie.Value = DDLArea1.SelectedIndex.ToString();
ddAreaCookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(ddAreaCookie);
}
public void DropDownCityIndexChange()
{
DDLArea1.Items.Clear();
DDLArea1.DataSource = null;
HttpCookie ddCityCookie = new HttpCookie("ddCityCookie");
ddCityCookie.Value = DDLCity1.SelectedIndex.ToString();
ddCityCookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(ddCityCookie);
DataSet ds = new DataSet();
if (DDLCity1.SelectedItem.Text != "- All India -")
{
DataTable dt = new DataTable();
dt = objsql.GetTable("select area from tblCity where city='" + DDLCity1.SelectedItem.Text + "' and status=1 order by area");
if (dt.Rows[0]["area"].ToString() != null && dt.Rows[0]["area"].ToString() != "")
{
DDLArea1.DataSource = dt;
DDLArea1.DataTextField = "area";
DDLArea1.DataValueField = "area";
DDLArea1.DataBind();
}
}
DDLArea1.Items.Insert(0, new ListItem("- Anywhere -", "- Anywhere -"));
}
</code>
remove ClientIDMode="Static" Propery
Related
I'm struggling a lot and I hope someone can help me please.
I have a 4 dropdownlists, a search button and a normal gridview with a basic SQLdataConnection.
The SQLdataConnection is a stored procedure that retrieves 3 tables based on 4 parameters. These 3 tables are then joined together into the gridview.
BUT
One of the dropdownlists has the options of Total, Fast and Slow. So based on which option the user chooses the respective table should be loaded into the gridview when the search button is pressed. (So if total is chosen, the total table should be loaded into the gridview)
I don't know if the SQLdataConnection should be changed with each option to show only the appropriate table.
Below is a copy of the html of the dropdowns and gridview as well as the code behind.
<tr>
<td style="text-align: right" class="pad-right-0">
<asp:DropDownList ID="selSeconds" runat="server" CssClass="selectbox select-chr" Visible="true"></asp:DropDownList>
<asp:DropDownList ID="selHours" runat="server" CssClass="selectbox select-chr" Visible="true"></asp:DropDownList>
<asp:DropDownList ID="selMerchantId" runat="server" CssClass="selectbox select-chr" Visible="true"></asp:DropDownList>
<asp:DropDownList ID="selTableType" runat="server" CssClass="selectbox select-chr" Visible="true"></asp:DropDownList>
<asp:Button ID="btnSearch" runat="server" CssClass="btn btn-primary btn-danger tip-s medium grey" ValidationGroup="Search" OnClick="btnSearch_Click" Text="<%$Resources:Resource, btnSearch %>" />
<asp:ImageButton ID="btnExportToExcel" runat="server" CssClass="btn btn-primary btn-danger tip-s medium grey" ValidationGroup="Search" onclick="btnExportToExcel_Click" Text="Export to excel" ImageUrl="images/Excel.png" AlternateText="<%$Resources:Resource, lblExportExcel %>"
CausesValidation="false" />
<asp:RequiredFieldValidator ID="rqrdMerchantId" runat="server" ErrorMessage="<%$Resources:Resource, lblRequired %>" ControlToValidate="selMerchantId" ForeColor="Red" />
</td>
</tr>
</table>
<asp:HiddenField ID="hdnMerchantId" runat="server" Value="0" />
<asp:GridView ID="gridSpeedAnalysis" runat="server" DataSourceID="gridSqlConnection">
</asp:GridView>
<asp:SqlDataSource ID="gridSqlConnection" runat="server"></asp:SqlDataSource>
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] == null || Session["UserType"] == null)
{
Response.Redirect("Login.aspx");
}
LoadDropDowns();
}
private void LoadDropDowns()
{
System.Web.UI.WebControls.ListItem item;
selSeconds.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Select Second", "0"));
int index = 1;
for (int Second = 0; Second <= 10; Second++)
{
System.Web.UI.WebControls.ListItem li = new System.Web.UI.WebControls.ListItem(Second.ToString(), Second.ToString());
selSeconds.Items.Insert(index, li);
index++;
}
item = selSeconds.Items.FindByValue(DateTime.Now.Year.ToString());
selSeconds.SelectedIndex = selSeconds.Items.IndexOf(item);
if (Session["UserType"] != null && (Session["UserType"].ToString().ToLower() == "System Administrator".ToLower()))
{
selMerchantId.DataSource = BOL.MerchantGroup.Load();
selMerchantId.DataTextField = "Description";
selMerchantId.DataValueField = "MerchantId";
selMerchantId.DataBind();
selMerchantId.Items.Insert(0, new System.Web.UI.WebControls.ListItem { Value = "0", Text = "Select Group" });
rqrdMerchantId.InitialValue = "0";
}
else if (Session["UserType"].ToString().ToLower() == "Head Office".ToLower())
{
BOL.MerchantGroup group = new BOL.MerchantGroup(int.Parse(hdnMerchantId.Value));
selMerchantId.Items.Insert(0, new System.Web.UI.WebControls.ListItem { Value = hdnMerchantId.Value, Text = group.Description });
}
DataTable dt = BOL.Merchant.GetDropdownByMerhcantGroupId(int.Parse(Session["MerchantGroupId"].ToString()));
selMerchantId.DataSource = dt;
selMerchantId.DataTextField = "Name";
selMerchantId.DataValueField = "MerchantId";
selMerchantId.DataBind();
selTableType.Items.Insert(0, new System.Web.UI.WebControls.ListItem {Text = "Total"});
selTableType.Items.Insert(0, new System.Web.UI.WebControls.ListItem {Text = "Fast" });
selTableType.Items.Insert(0, new System.Web.UI.WebControls.ListItem {Text = "Slow" });
}
protected void btnSearch_Click(object sender, EventArgs e)
{
}
I have one page where I am making use of Update panel, Datalist and file upload. I am using visual studio 2010.
My fileupload is in data list and I am binding data list with dynamic table to repeat the file upload control.
Please see below layout image:
Here Main upper red highlighted border is showing the repeated data list and in that I have file upload control.
Now the data list is in Update Panel so the file upload was not working So in data list I have taken another update panel to make file upload work and that was also working properly but on clicking of green add button issue started arising as
A control with ID 'Upload' could not be found for the trigger in
UpdatePanel 'UpdatePanel1'.
Below is my html code and please remember I am just giving the part where issue is arises:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="Uppanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DataList ID="dtcustomerregistration" runat="server" RepeatDirection="Vertical"
Width="100%" OnItemCommand="dtcustomerregistration_ItemCommand">
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<label class="col-md-4 control-label" for="Pic">
Upload Image:</label>
<asp:FileUpload ID="Pic" runat="server" accept="image/gif, image/jpg, image/jpeg, image/png" />
<asp:Button ID="Upload" CommandArgument='<%#Eval("uniqueId") %>' CommandName="Edit"
runat="server" Text="Upload" OnClick="Upload_Click" />
<asp:Label ID="StatusLabel" runat="server" CssClass="requiredvalidate" Text=""></asp:Label>
<asp:HiddenField ID="hdimagename" runat="server" Value='<%#Eval("UploadImage") %>' />
<asp:Image ID="imgpicuploaded" runat="server" ImageUrl='<%#System.Configuration.ConfigurationManager.AppSettings["ShowImagetemppath"].ToString().Replace("~/","") +Eval("UploadImage").ToString() %>'
Height="50px" />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Upload" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
</asp:DataList>
<asp:ImageButton ID="imgplus" runat="server" ImageUrl="~/Image/Add.png" Height="50px" OnClick="imgplus_Click" />
</ContentTemplate>
</asp:UpdatePanel>
My code on imgplus click event is as below.
protected void imgplus_Click(object sender, ImageClickEventArgs e)
{
int n = (int)ViewState["n"];
n = n + 1;
BindData(n);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["data"] = null;
BindData(0);
}
}
public void BindData(int n)
{
DataTable dt = new DataTable();
dt.Columns.Add("uniqueId");
dt.Columns.Add("Invoice");
dt.Columns.Add("ReturnType");
dt.Columns.Add("ItemNumber");
dt.Columns.Add("ReturnQTY");
dt.Columns.Add("UnitofMeasure");
dt.Columns.Add("CreditPer");
dt.Columns.Add("ReasonCode");
dt.Columns.Add("InvoiceNumber");
dt.Columns.Add("Ordernumber");
dt.Columns.Add("Notes");
dt.Columns.Add("UploadImage");
if (ViewState["data"] == null)
{
dt = bindemptydata(dt, n);
}
else
{
foreach (DataListItem dli in dtcustomerregistration.Items)
{
HiddenField lblid = (HiddenField)dli.FindControl("lblid");
DropDownList RetCred = (DropDownList)dli.FindControl("RetCred");
DropDownList returntype = (DropDownList)dli.FindControl("returntype");
TextBox ItemNumber = (TextBox)dli.FindControl("ItemNumber");
TextBox ReturnQty = (TextBox)dli.FindControl("ReturnQty");
DropDownList Unit = (DropDownList)dli.FindControl("Unit");
TextBox Credit = (TextBox)dli.FindControl("Credit");
DropDownList ReasonCode = (DropDownList)dli.FindControl("ReasonCode");
TextBox Invoice = (TextBox)dli.FindControl("Invoice");
TextBox OrderNumber = (TextBox)dli.FindControl("OrderNumber");
TextBox Notes = (TextBox)dli.FindControl("Notes");
Image imgpicuploaded = (Image)dli.FindControl("imgpicuploaded");
HiddenField hdimagename = (HiddenField)dli.FindControl("hdimagename");
DataRow dr = dt.NewRow();
if (lblid.Value != "")
{
dr["uniqueId"] = lblid.Value;
}
else
{
dr["uniqueId"] = n;
}
dr["Invoice"] = RetCred.SelectedValue;
dr["ReturnType"] = returntype.SelectedValue;
dr["ItemNumber"] = ItemNumber.Text;
dr["ReturnQTY"] = ReturnQty.Text;
dr["UnitofMeasure"] = Unit.SelectedValue;
dr["CreditPer"] = Credit.Text;
dr["ReasonCode"] = ReasonCode.SelectedValue;
dr["InvoiceNumber"] = Invoice.Text;
dr["Ordernumber"] = OrderNumber.Text;
dr["Notes"] = Notes.Text;
dr["UploadImage"] = hdimagename.Value;
dt.Rows.Add(dr);
}
dt = bindemptydata(dt, n);
}
BindDatalist(dt);
ViewState["n"] = n;
}
public DataTable bindemptydata(DataTable dt, int n)
{
DataRow dr = dt.NewRow();
dr["uniqueId"] = n;
dr["Invoice"] = "Credit";
dr["ReturnType"] = "0";
dr["ItemNumber"] = "";
dr["ReturnQTY"] = "";
dr["UnitofMeasure"] = "Each";
dr["CreditPer"] = "100%";
dr["ReasonCode"] = "0";
dr["InvoiceNumber"] = "";
dr["Ordernumber"] = "";
dr["Notes"] = "";
dr["UploadImage"] = "";
dt.Rows.Add(dr);
return dt;
}
public void BindDatalist(DataTable dt)
{
dtcustomerregistration.DataSource = dt;
dtcustomerregistration.DataBind();// Here I am receiving error
ViewState["data"] = dt;
}
Here above I had given full code to create the dynamic data table and binding that with data list so that data list get repeated on click of imgplus button
But on click of button I am receiving error as :
Below is the error image.
How can I fix this?
On Click on Imgplus button I m receiving issue for upload button which exist in DataList.
And one more thing that if I normally click ImgPlus button without having use of Upload button click then it will repeat the DataList control without giving any issue but in case Once I made use of Upload click button exist in DataList and then after I click Imgplus button I receive error as:
A control with ID 'Upload' could not be found for the trigger in
UpdatePanel 'UpdatePanel1'.
Surround your button with another UpdatePanel upButton:
<asp:UpdatePanel ID="upButton" runat="server" UpdateMode="Conditional">
<asp:Button ID="Upload" CommandArgument='<%#Eval("uniqueId") %>' CommandName="Edit"
runat="server" Text="Upload" OnClick="Upload_Click" />
</ContentTemplate>
And then call your main UpdatePanel Uppanel.Update(); in your button click method Upload_Click.
Note: Remove UpdatePanel ID="UpdatePanel1".
You're error happens because of this code:
<Triggers>
<asp:PostBackTrigger ControlID="Upload" />
</Triggers>
You used PostBackTrigger while you are inside a nested pannel, while you shoud use
AsyncPostBackTrigger in this case as per this page.
So change that code segment to be:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Upload" />
</Triggers>
or set the UpdateMode of UpdatePanel1 to be "Always"
I want to force the user to change the selection of the first drop down list IF he/she selected a particular value in the second drop down list.
<asp:DropDownList ID="ddlGxP" runat="server" CssClass="stdDropdownSmall" OnSelectedIndexChanged="ddlGxP_SelectedIndexChanged" AutoPostBack="true" />
<
else
{
}
The above is the first drop down list where the user should select value from "ddlGxP"
The following is the second drop down list where I need to make the check when the user make a selection, I have to check on the first drop down.
<div class="divStandard">
<asp:Label ID="Label23" runat="server" CssClass="stdLabel">nalized Method <span class="mandatory"> *</span></asp:Label>
<asp:DropDownList ID="ddlFinalizedMethod" runat="server" CssClass="stdDropdown" />
<asp:CustomValidator ID="cvFinalizedMethod" runat="server" ControlToValidate="ddlFinalizedMethod" InitialValue="0" OnServerValidate="cvFinalizedMethod_ServerValidate"
CssClass="RequiredFieldError" ErrorMessage=" ! Please select another GxP Standard" />
} else {
<asp:TextBox ID="txtFinalizedMethodDisabled" runat="server" CssClass="stdTextboxSmallDisabled" Enabled="false" />
}
</div>
i don't have enough reputation so here is my comment.
i just want to clarify the problem in basic terms.
your design view consists of two dropdownlists.
you make a selection on dropdownlist1, its selectedindexchanged is triggered performing some sort of action.
you now make a selection on dropdownlist2, its selectedindexchanged is triggered and performs some sort of manipulation on dropdownlist1, either changing its contents or selected value;
SORRY FOR THE WAIT, I MADE SOME SIMPLE ERRORS DUE TO FORGETTING SOME THINGS;
The ANSWER!!!!
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
onselectedindexchanged="ddl2_selectindexchange">
</asp:DropDownList>
</div>
</form>
</body>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<string> str = new List<string>();
str.Add("red");
str.Add("blue");
str.Add("black");
List<string> str2 = new List<string>();
str2.Add("red");
str2.Add("blue");
str2.Add("black");
DropDownList1.DataSource = null;
DropDownList1.DataSource = str;
DropDownList1.DataBind();
DropDownList2.DataSource = null;
DropDownList2.DataSource = str2;
DropDownList2.DataBind();
}
}
protected void ddl2_selectindexchange(object sender, EventArgs e)
{
DropDownList ddl = new DropDownList();
ddl = sender as DropDownList;
ListItem li = new ListItem();
li = ddl.SelectedItem;
string s = li.Text;
Label1.Text = s;
}
I have a two listboxes and a button. I need to add selected item from one listbox to another with click of button.
and here is the code of the button
protected void ASPxButton4_Click(object sender, EventArgs e)
{
if (listBoxSubeKiyaslama1.SelectedIndex > -1)
{
listBoxSubeKiyaslama2.Items.Add(listBoxSubeKiyaslama1.SelectedItem);
listBoxSubeKiyaslama2.Items.RemoveAt(listBoxSubeKiyaslama1.SelectedIndex);
listBoxSubeKiyaslama2.UnselectAll();
}
}
when I click the button, I see that listBoxSubeKiyaslama1.SelectedIndex is always "-1". because I think it postbacks and clears items from the first listbox. How can I fix this?
Can you try the below code:
if (listBoxSubeKiyaslama1.SelectedItem != null)
{
listBoxSubeKiyaslama2.Items.Add(listBoxSubeKiyaslama1.SelectedItem);
listBoxSubeKiyaslama2.Items.RemoveAt(listBoxSubeKiyaslama1.SelectedIndex);
listBoxSubeKiyaslama2.UnselectAll();
}
The controls will be not save the values on postbacks if EnableViewState = false. By default it is true. Please make sure you are not setting it to false.
I also suggest you to put your control in UpdatePanel to avoid full postback.
Like:
<asp:UpdatePanel ID="up1" runat="Server">
<ContentTemplate>
<asp:ListBox ID="listBoxSubeKiyaslama1" runat="server">
</asp:ListBox>
<asp:ListBox ID="listBoxSubeKiyaslama2" runat="server">
</asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
Try the following code:-
ASPX.CS
public string GetSelectedItems(ListBox control)
{
var items = new StringBuilder();
foreach (ListItem item in control.Items)
{
if (item.Selected)
items.Append(string.Format("{0},", item.Value));
}
return items.ToString().Trim().TrimEnd(',');
}
protected void btnMoveRight_Click(object sender, EventArgs e)
{
for (int i = lbCourses1.Items.Count - 1; i >= 0; i--)
{
if (lbCourses1.Items[i].Selected == true)
{
lbCourses2.Items.Add(lbCourses1.Items[i]);
ListItem li = lbCourses1.Items[i];
lbCourses1.Items.Remove(li);
}
}
}
protected void btnMoveLeft_Click(object sender, EventArgs e)
{
for (int i = lbCourses2.Items.Count - 1; i >= 0; i--)
{
if (lbCourses2.Items[i].Selected == true)
{
lbCourses1.Items.Add(lbCourses2.Items[i]);
ListItem li = lbCourses2.Items[i];
lbCourses2.Items.Remove(li);
}
}
}
var selectedValues = GetSelectedItems(lb2);
ASPX
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<asp:Label ID="lbl1" runat="server" Text="lbl1:"></asp:Label>
<asp:ListBox ID="lb1" runat="server" SelectionMode="Multiple"></asp:ListBox>
<asp:Button Runat="server" ID="btnMoveRight" Text=">>"
onclick="btnMoveRight_Click"></asp:Button>
<asp:Button Runat="server" ID="btnMoveLeft" Text="<<"
onclick="btnMoveLeft_Click"></asp:Button>
<asp:ListBox ID="lb2" runat="server" SelectionMode="Multiple"></asp:ListBox>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I have 2 dropdownlists on my page. One for activity and one for sub activity. When the activity dropdownlist changes I retrieve the values for the sub activity dropdownlist . I am using a updatepanel for the second dropdownlist and the trigger is set to the first dropdownlist. This is working magicly until I leave the page to idle for a while 1-2min max. When I change the value for the activity dropdownlist(the trigger) it causes a full postback and the items for the second dropdownlist does not get populated.
Here is my code below.
Aspx
<div class="form-line">
<label>Activity</label>
<asp:DropDownList ID="ddlActivity" required="required" CssClass="chosen-select" runat="server" Width="200px" AppendDataBoundItems="true" OnSelectedIndexChanged="SelectedActivity_Changed" AutoPostBack="true" CausesValidation="false">
</asp:DropDownList>
</div>
<div class="form-line">
<label>Sub Activity</label>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlActivity" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="ddlSubActivity" runat="server" Width="200px" required="required" CssClass="chosen-select" AppendDataBoundItems="true" CausesValidation="false">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Code behind
[ToolboxItemAttribute(false)]
public partial class MyEstimatesAdd : WebPart
{
static string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
ChronoLogDataContext dc = new ChronoLogDataContext(connStr);
// Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
// using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
// for production. Because the SecurityPermission attribute bypasses the security check for callers of
// your constructor, it's not recommended for production purposes.
// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
public MyEstimatesAdd()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Page.Request.QueryString["Issue_ID"] != "" && Page.Request.QueryString["Issue_ID"] != null)
{
Int64 issueid = Int64.Parse(Page.Request.QueryString["Issue_ID"]);
string sCurrentUserEmail;
SPUser cuser = SPControl.GetContextWeb(Context).CurrentUser;
sCurrentUserEmail = cuser.Email;
dc = new ChronoLogDataContext(connStr);
var resource = (from r in dc.RESOURCEs
where r.Email == sCurrentUserEmail
select r).FirstOrDefault();
ddlActivity.DataSource = (from a in dc.ACTIVITY_CATEGORies
select a).ToList();
ddlActivity.DataValueField = "Activity_Category_ID";
ddlActivity.DataTextField = "Description";
ddlActivity.DataBind();
ddlActivity.Items.Insert(0, new ListItem("", ""));
}
}
}
//RUN AGAIN PRIMARY SET
protected void btnAdd_Click(object sender, EventArgs e)
{
int hours;
if (!int.TryParse(txtHours.Text, out hours))
{
throw new SPException("Hours must be a numeric value");
}
string sCurrentUserEmail;
SPUser cuser = SPControl.GetContextWeb(Context).CurrentUser;
sCurrentUserEmail = cuser.Email;
dc = new ChronoLogDataContext(connStr);
var resource = (from r in dc.RESOURCEs
where r.Email == sCurrentUserEmail
select r).FirstOrDefault();
Int64 issueid = Int64.Parse(Page.Request.QueryString["Issue_ID"]);
decimal time = decimal.Parse(hours + "." + ddlMinutes.SelectedValue.ToString(), CultureInfo.InvariantCulture);
ESTIMATE estimate = new ESTIMATE { Activity_ID = int.Parse(ddlActivity.SelectedItem.Value), Date_Captured = DateTime.Now, Estimated_Time = time, Features = txtFeatures.Text, Issue_ID = issueid, Resource_ID = resource.Resource_ID, Sub_Activity_ID = int.Parse(ddlSubActivity.SelectedItem.Value) };
dc.ESTIMATEs.InsertOnSubmit(estimate);
dc.SubmitChanges();
Close_Save();
}
protected void Close_Save()
{
HttpContext context = HttpContext.Current;
if (HttpContext.Current.Request.QueryString["IsDlg"] != null)
{
context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup()</script>");
context.Response.Flush();
context.Response.End();
}
}
protected void SelectedActivity_Changed(object sender, EventArgs e)
{
int activityid = int.Parse(ddlActivity.SelectedItem.Value);
dc = new ChronoLogDataContext(connStr);
var subactivities = (from s in dc.ACTIVITY_SUBCATEGORies
where s.Activity_Category_ID == activityid
select s).ToList();
ddlSubActivity.Items.Clear();
ddlSubActivity.DataSource = subactivities;
ddlSubActivity.DataValueField = "Activity_SubCategory_ID";
ddlSubActivity.DataTextField = "Description";
ddlSubActivity.DataBind();
ddlSubActivity.Items.Insert(0, new ListItem("", ""));
UpdatePanel1.Update();
}
}
Put both drop down lists within the same UpdatePanel or each in their own UpdatePanel, like this:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlActivity" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<div class="form-line">
<label>Activity</label>
<asp:DropDownList ID="ddlActivity" required="required" CssClass="chosen-select" runat="server" Width="200px" AppendDataBoundItems="true" OnSelectedIndexChanged="SelectedActivity_Changed" AutoPostBack="true" CausesValidation="false">
</asp:DropDownList>
</div>
<div class="form-line">
<label>Sub Activity</label>
<asp:DropDownList ID="ddlSubActivity" runat="server" Width="200px" required="required" CssClass="chosen-select" AppendDataBoundItems="true" CausesValidation="false">
</asp:DropDownList>
</div>
</ContentTemplate>
</asp:UpdatePanel>