How to prevent one update panel from affecting another c# asp - c#

My problem is the following, when I first use the droplist of the first updatepanel to function correctly it shows me the label and textbox that are hidden, everything works fine.
But, when I use first the dropProvince, canton or district, they implement the method
protected void
droplistTipoIdentificacionDatosPropietario_SelectedIndexChanged (object sender, EventArgs and )
{
MessageBox.Show ("hello");
this.datosPropietarioLblNumIdentificacion.Visible = true;
this.datosPropietariotxtNumIdentificacion.Visible = true;
}
each drop has its own method
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.datosPropietarioLblNumIdentificacion.Visible = false;
this.datosPropietariotxtNumIdentificacion.Visible = false;
}
}
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" Text="Tipo de Identificación"></asp:Label>
<asp:DropDownList ID="droplistTipoIdentificacionDatosPropietario"
runat="server"
Width="100%"
Height="30px"
AutoPostBack="true"
OnSelectedIndexChanged="droplistTipoIdentificacionDatosPropietario_SelectedIndexChanged">
<asp:ListItem Text="Cédula Identidad" Value="C"></asp:ListItem>
<asp:ListItem Text="Cédula de Residencia" Value="R"></asp:ListItem>
<asp:ListItem Text="Cédula Jurídica" Value="J"></asp:ListItem>
<asp:ListItem Text="Pasaporte" Value="P"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
Code Behind call
protected void droplistTipoIdentificacionDatosPropietario_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("hola");
this.datosPropietarioLblNumIdentificacion.Visible = true;
this.datosPropietariotxtNumIdentificacion.Visible = true;
}
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="grid3">
<asp:Label runat="server" Text="Provincia"></asp:Label>
<asp:DropDownList ID="droplistProvincia"
AutoPostBack="true" onchange="testProvincia"
OnSelectedIndexChanged="droplistProvincia_SelectedIndexChanged"
Width="100%" runat="server" Height="30px">
<asp:ListItem Text="Seleccione"></asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" Text="Cantón"></asp:Label>
<asp:DropDownList ID="droplistCanton" CssClass="item15"
AutoPostBack="true"
OnSelectedIndexChanged="droplistCanton_SelectedIndexChanged"
Width="100%" runat="server" Height="30px">
<asp:ListItem Text="Seleccione"></asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" CssClass="item16" Text="Distrito"></asp:Label>
<asp:DropDownList ID="droplistDistrito"
AutoPostBack="true"
OnSelectedIndexChanged="droplistDistrito_SelectedIndexChanged"
CssClass="item17" runat="server" Height="30px">
<asp:ListItem Text="Seleccione"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>

You might have a copy/paste issue; sometimes copy/paste will not execute code. Try deleting the code-behind methods from each dropdown and re-adding them.
<asp:DropDownList ID="droplistProvincia"
AutoPostBack="true" onchange="testProvincia"
OnSelectedIndexChanged="droplistProvincia_SelectedIndexChanged" <- delete this
Width="100%" runat="server" Height="30px">
<asp:ListItem Text="Seleccione"></asp:ListItem>
</asp:DropDownList>
Delete the line as shown above, and also delete the code-behind. Re-add by double-clicking the dropdown list.
Hope that helps. It's hard to tell what the problem is from your question.

Related

Changing Label text on ListBox event is not working while outside of UpdatePanel

I have the code below for a ListBox:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server" onselectedindexchanged="ListBox1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="0">Item1</asp:ListItem>
<asp:ListItem Value="1">Item2</asp:ListItem>
<asp:ListItem Value="2">Item3</asp:ListItem>
</asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:Label ID="lblTB" runat="server"/>
And this is the code behind the index changed event:
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
lblTB.Text = "You choose: " + ListBox1.SelectedItem.Text;
}
I don't want to put control label into UpdatePanel. How can I make this code run? Thanks all.
Code looks fine just add ScriptManager.Try this:
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ListBox1" runat="server"
onselectedindexchanged="ListBox1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="0">Item1</asp:ListItem>
<asp:ListItem Value="1">Item2</asp:ListItem>
<asp:ListItem Value="2">Item3</asp:ListItem>
</asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Label ID="lblTB" runat="server"/>
Code behind should be.
try
{
HttpCookie getcook = Request.Cookies["saveme"];
string check = getcook["saveme"].ToString();
if (getcook["saveme"].Length > 0 && getcook["saveme"].ToString()!="none")
{
lblTB.Text = getcook["saveme"].ToString();
}
}
catch(Exception er)
{
HttpCookie cookie = new HttpCookie("saveme");
cookie["saveme"] = "none";
Response.Cookies.Add(cookie);
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
lblTB.Text = "You choose: " + ListBox1.SelectedItem.Text;
HttpCookie setcook =Request.Cookies["saveme"];
setcook["saveme"] = lblTB.Text;
setcook.Expires = DateTime.Now.AddDays(1d); ;
Response.Cookies.Add(setcook);
Response.Redirect("updatepanelhere.aspx", false);
}

Set id for multiple radio buttons list generated by a repeater

Is there a way to set the ID for multiple radiobuttonlists generated via repeater.
ie. ID= rep1 rep2 rep3 rep4
I would like to be able to place my data in multiple columns across a table.
Heres is my code so far:
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%: Title %></h2>
<h3>Your application description page.</h3>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label ID="lblQuestion" runat="server" Text='<%# Eval("Text") %>' />
<asp:RadioButtonList ID="ddlAnswer" runat="server" AutoPostBack="True" RepeatDirection="Horizontal">
<asp:ListItem Text="Yes" Value="True" />
<asp:ListItem Text="No" Value="False" />
</asp:RadioButtonList>
<asp:Panel ID="Panel1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Provide more details:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Panel>
</p>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT [Text] FROM [Questions]"></asp:SqlDataSource>
Behind:
protected void Page_Load(object sender, EventArgs e)
{
foreach (RepeaterItem item in Repeater1.Items)
{
RadioButtonList ddlAnswer = item.FindControl("ddlAnswer") as RadioButtonList;
System.Web.UI.WebControls.Panel Panel1 = item.FindControl("Panel1") as System.Web.UI.WebControls.Panel;
if (ddlAnswer.SelectedValue == "False")
{
Panel1.Visible = true;
}
else
{
Panel1.Visible = false;
}
}
}
You can just use ClientIdMode="Predictable" attribute in the aspx mark-up to assign different ids to different dropdownlists like this:
<asp:RadioButtonList ClientIDMode="Predictable" ID="ddlAnswer" runat="server" AutoPostBack="True" RepeatDirection="Horizontal"> ...

update panel is not working on asp.net code

This is my c# code behind
protected void callDispositionChanged(object sender, EventArgs e)
{
var dropDown = (DropDownList)ListView1.FindControl("callDispositionSelector");
var visitID = (TextBox)ListView1.FindControl("visitID");
if (dropDown != null)
{
Response.Write(dropDown.SelectedValue + "ssssssssss");
visitID.Text = dropDown.SelectedValue;
}
else
{
visitID.Text = "ffffff";
Response.Write("FFFFFFFFFFFFFFFF");
}
}
this is my asp code
<asp:UpdatePanel ID="UpdatePanel3" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<tr class="footer" runat="server">
<td colspan="4" runat="server">* By VoiceMpower
<asp:DropDownList AutoPostBack="true" runat="server" ID="callDispositionSelector" OnSelectedIndexChanged="callDispositionChanged" clientidmode="Static">
<asp:ListItem Value="-1">Select Disposition Reason</asp:ListItem>
<asp:ListItem Value="1">Reservation</asp:ListItem>
<asp:ListItem Value="2">Change of Reservation</asp:ListItem>
<asp:ListItem Value="3">Cancellation</asp:ListItem>
<asp:ListItem Value="4">Wait List</asp:ListItem>
<asp:ListItem Value="5">Other</asp:ListItem>
</asp:DropDownList>
<asp:TextBox runat="server" ID="visitID" clientidmode="Static"></asp:TextBox>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
when I change the value of the select, the function is executed, but the results (the post back page) has the select in the devaul vaule.
note
i already have
<asp:ScriptManager ID="ScriptManager2" runat="server" />
note 3
that asp code exist in item template in asp.listview
Note2
I can't debug the project because the database on the server and I am not allowed to make a link to it. So each time i develop a functoin, I go and deploy the website on the server and test it. So please let your answers without making break points and something like that. thanks in advance
You are using Conditional Mode which means, the update panel will not work, unless the event is triggered.
Remove that.
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<tr class="footer" runat="server">
<td colspan="4" runat="server">* By VoiceMpower
<asp:DropDownList AutoPostBack="true" runat="server" ID="callDispositionSelector" OnSelectedIndexChanged="callDispositionChanged" ClientIDMode="Static">
<asp:ListItem Value="-1">Select Disposition Reason</asp:ListItem>
<asp:ListItem Value="1">Reservation</asp:ListItem>
<asp:ListItem Value="2">Change of Reservation</asp:ListItem>
<asp:ListItem Value="3">Cancellation</asp:ListItem>
<asp:ListItem Value="4">Wait List</asp:ListItem>
<asp:ListItem Value="5">Other</asp:ListItem>
</asp:DropDownList>
<asp:TextBox runat="server" ID="visitID" ClientIDMode="Static"></asp:TextBox>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>

RadioButtonList set to AutoPostBack = true but still not firing OnSelectedIndexChanged

I have 2 RadioButtonLists and I want only one option to be selected, f.i. if you select an option in List 1 the selection in List 2 should be cleared.
AutoPostBack and EnableViewState is set to true, but still the Method never fires. I have also checked if the Index actually changes, it does. I think that the PostBack just doesn't occur, but I don'T know why.
I'm thankful for any help.
ascx:
<asp:RadioButtonList ID="_listOne" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ListOneIndexChanged">
</asp:RadioButtonList>
<asp:RadioButtonList ID="_listTwo" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ListTwoIndexChanged">
</asp:RadioButtonList>
Code Behind:
protected void ListOneIndexChanged(object sender, EventArgs e)
{
_listTwo.ClearSelection();
}
protected void ListTwoIndexChanged(object sender, EventArgs e)
{
_listOne.ClearSelection();
}
change the control to RadioButton and add GroupName to them will do the trick:
<asp:RadioButton ID="_listOne" runat="server" GroupName="xx" AutoPostBack="true" OnSelectedIndexChanged="ListOneIndexChanged">
</asp:RadioButton>
<asp:RadioButton ID="_listTwo" runat="server" GroupName="xx" AutoPostBack="true" OnSelectedIndexChanged="ListTwoIndexChanged">
</asp:RadioButton>
try to use just one radibuttonlist and options.
<asp:RadioButtonList id="radiolist1" runat="server" OnSelectedIndexChanged="ListOneIndexChanged">
<asp:ListItem selected="true">Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
</asp:RadioButtonList>

asp.net drop downlist value reset on button click within jquery dialog

I have a div , within which I have a button and an asp.net dropdownlist. I can change the value in the dropdownlist . But as soon as the button is clicked the value in the drop down list is again set to the default initial value. Is there a way I can solve this problem ? I do not want the dropdownlist to go back to its initial value.
aspx
<div id='one'>
<asp:LinkButton ID="ConfigureAlerts" OnClick="btnConfigureAlerts_Click" runat="server">Configure Alerts</asp:LinkButton>
</div>
<div id="ViewModalPopupDiv2">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel2" runat="server" HorizontalAlign="left" ScrollBars="Auto">
<asp:Button ID="btnGetLogs" runat="server" Text="SendAlerts" OnClick="btnSendAlertEmail_Click"/>
<asp:Label ID="Label2" runat="server" Text="Set The Alert Email Interval to every :" CssClass="label"
ForeColor="Black"></asp:Label>&nbsp&nbsp&nbsp
<asp:DropDownList ID="ddlTimeInterval" runat="server" >
<asp:ListItem Text="15MIN" Value="15"></asp:ListItem>
<asp:ListItem Text="30MIN" Value="30"></asp:ListItem>
<asp:ListItem Text="1Hr" Value="60"></asp:ListItem>
<asp:ListItem Text="2Hrs" Value="120"></asp:ListItem>
<asp:ListItem Text="8Hrs" Value="480"></asp:ListItem>
<asp:ListItem Text="24Hrs" Value="1440"></asp:ListItem>
<asp:ListItem Text="48Hrs" Value="2880"></asp:ListItem>
</asp:DropDownList>
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
javascript
function ViewModelPopup2() {
$("#ViewModalPopupDiv2").dialog({
scrollable: true,
width: 800,
modal: true
});
}
ASPX.CS
protected void btnSendAlertEmail_Click(object sender, EventArgs e)
{
// Code to send email
}
protected void btnConfigureAlerts_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript
(this, this.GetType(), "callScriptFunction", "ViewModelPopup2();", true);
}
}
The problem i can see is that , JQuery and Update Panel. These two never works together properly. You need to remove either. But there is a work around. Check out this one.http://www.codeproject.com/Articles/601683/Working-with-jQuery-within-the-ASP-NET-UpdatePanel

Categories