Showing posts with label dear. Show all posts
Showing posts with label dear. Show all posts

Wednesday, March 28, 2012

Dynamic controls problem.

dear All

I have a checkbox (dynamically generated) and a label.

when the checkbox is changed, I want to change the labels text property. and also put a dynamic DropDownlist box on thr form.

when the Dropdownlist box selected value is changed, I want to again change the value of the labels text to something else. The checkbox behaves properly, but the DropDownList box when selected doesnt do ANYTHING. NOTE: I put the label in a update panel and call the panel.update() method. I put both the .cs and .aspx codes below.

aspx code

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <asp:PlaceHolder ID="PlaceHolder1" runat="server"> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </asp:PlaceHolder> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>


aspx.cs code

using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partialclass _Default : System.Web.UI.Page { CheckBox CheckBox1 =new CheckBox(); DropDownList Dropdownlist1 =new DropDownList();protected void Page_Load(object sender, EventArgs e) { Label1.Text ="page has loaded"; addCheckBox(); CheckBox1.AutoPostBack =true; ScriptManager1.RegisterAsyncPostBackControl(CheckBox1);//adddropdownlist(); CheckBox1.CheckedChanged +=new EventHandler(CheckBox1_CheckedChanged); Dropdownlist1.AutoPostBack =true; ScriptManager1.RegisterAsyncPostBackControl(Dropdownlist1); Dropdownlist1.SelectedIndexChanged +=new EventHandler(DropDownList1_SelectedIndexChanged); }private void adddropdownlist() { Dropdownlist1.Items.Add("first"); Dropdownlist1.Items.Add("second"); Dropdownlist1.Items.Add("thirs"); PlaceHolder1.Controls.Add(Dropdownlist1); }private void addCheckBox() { CheckBox1.Text ="tickme"; CheckBox1.ID ="checkbox1"; PlaceHolder1.Controls.Add(CheckBox1); }void CheckBox1_CheckedChanged(object sender, EventArgs e) { Label1.Text ="checkbox has been ticked"; adddropdownlist(); UpdatePanel1.Update(); }void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text ="Page has reloaded"; UpdatePanel1.Update(); }}

Thanks in advance,

prasad..

bumping--please help me.

This doesn't have to do with AJAX (try removing the UpdatePanel to see).

I highly recommend this 4-part series on dynamic controls in ASP.NET:http://devsushi.com/2006/08/27/aspnet-dynamic-control-creation-part-1/

The behavior I see with your code is that when I change the dropdown, the page goes back to its initial state ("page has loaded" and a checkbox). This makes sense, because when you change the dropdown, the page posts back, and in that postback, you don't create the dropdown. That means there's no control to hook up to, and the SelectedIndexChanged event doesn't fire. What you need to do is create the dropdown on every postback where you need to use it.

I recommend adding the dropdown to the placeholder in Page_Loadall the time, and setting Dropdownlist1.Visible = false. Then set Dropdownlist1.Visible = true when you want to display it. That way its events will still hook up properly when it causes a postback.

I hope that makes sense, but if it doesn't, the article I pointed to above should help a great deal. This can be confusing.


thank you for the link to the article. now I realise...what really a postback is. This was my first attempt at programming...:)

thank you,

prasad.

Saturday, March 24, 2012

DropDownList inside UpdatePanel

Dear All,

I have two DropDownList inside an UpdatePanel.

When I refresh the updatepanel the two DropDownList disappare for few second's, can I avoid it ?

Hi,

did you set the EnablePartialRendering attribute of the ScriptManager to "true"? If so, could you post the relevant code?

Yes EnablePartialRendering is set to true.

this is the code :

<%@. Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>

<script runat="server">


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Page.IsValid Then
If Page.IsValid Then


Dim stemp() As String
Dim ds As New WSUniprof.DScliente

Dim myrow As WSUniprof.DScliente.clienteRow = ds.cliente.NewclienteRow

myrow.Anagrafica = Me.TXRagioneSociale.Text.ToUpper.Trim
myrow.PartitaIva = Me.TXPartitaIva.Text.Trim
myrow.Indirizzo = Me.TXSedeLegale.Text.Trim

stemp = Me.DropDownList2.SelectedValue.Split("/")
If IsNumeric(stemp(0)) Then myrow.IDComune = stemp(0)

myrow.Cap = Me.TXCap.Text.ToString.Trim
myrow.Telefono = Me.TXTelefono.Text.ToString.Trim
myrow.Fax = Me.TXFax.Text.ToString.Trim
myrow.AltriTelefoni = Me.TXCellulare.Text.ToString.Trim
myrow.EMailInternet = Me.TXEmail.Text.Trim
myrow.IndirizzoS = Me.TXIndirizzoScarico.Text.Trim

stemp = Me.DropDownList4.SelectedValue.Split("/")
If IsNumeric(stemp(0)) Then myrow.IDComuneS = stemp(0)

myrow.CapS = Me.TXCapScarico.Text.ToString.Trim
myrow.TelefonoS = Me.TXTelefonoScarico.Text.ToString.Trim
myrow.FaxS = Me.TXFaxScarico.Text.ToString.Trim

ds.cliente.AddclienteRow(myrow)

Dim WEBserv As New WSUniprof.ClassCliente
' If WEBserv.IserimentoCliente(ds, Session("IDAnagrafica"), "malbec10") > 0 Then
Me.BloccaControlli()
Me.LabelCodiceCliente.Visible = True
Me.TXCodiceCliente.Visible = True
Me.TXCodiceCliente.Text = "12321"
System.Threading.Thread.Sleep(3000)
'Else

' End If

'SE PROVIENE DALLA PAGINA DI INSERIMENTO ORDINE
' If Request.QueryString("fromOrd") = "1" Then
'Response.Redirect("infoOrdine.aspx", False)
' Else
' Response.Redirect("default.aspx", False)
' End If
End If
End If
End Sub

Private Sub BloccaControlli()
Me.TXCap.Enabled = False
Me.TXCapScarico.Enabled = False
Me.TXCellulare.Enabled = False
Me.TXEmail.Enabled = False
Me.TXFax.Enabled = False
Me.TXFaxScarico.Enabled = False
Me.TXIndirizzoScarico.Enabled = False
Me.TXPartitaIva.Enabled = False
Me.TXPartitaIva.Enabled = False
Me.TXRagioneSociale.Enabled = False
Me.TXSedeLegale.Enabled = False
Me.TXRagioneSociale.Enabled = False
Me.TXSedeLegale.Enabled = False
Me.TXTelefono.Enabled = False
Me.TXTelefonoScarico.Enabled = False
Me.DropDownList1.Enabled = False
Me.DropDownList2.Enabled = False
Me.DropDownList3.Enabled = False
Me.DropDownList4.Enabled = False
Me.Label1.Enabled = False
Me.Label2.Enabled = False
Me.Label3.Enabled = False
Me.Label4.Enabled = False
Me.Label5.Enabled = False
Me.Label6.Enabled = False
Me.Label7.Enabled = False
Me.Label8.Enabled = False
Me.Label9.Enabled = False
Me.Label10.Enabled = False
Me.Label11.Enabled = False
Me.Label12.Enabled = False
Me.Label13.Enabled = False
Me.Label14.Enabled = False
Me.Label16.Enabled = False
Me.Label17.Enabled = False
Me.Label18.Enabled = False


End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script language="javascript" type="text/javascript">
function StartInsert(){
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false){
$('ctl00$ContentPlaceHolder1$Button1').disabled = true;
}

}
</script>
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 15px">
<tr>
<td align="center" style="width: 100%; height: 15px">
<asp:Label ID="Label1" runat="server" Text="Inserimento nuovo cliente"></asp:Label></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 400px">
<tr>
<td align="center" style="width: 100%; padding-top: 15px" valign="top">
<atlas:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="width: 400px; height: 300px; border-right: activeborder 1px solid; border-top: activeborder 1px solid; border-left: activeborder 1px solid; border-bottom: activeborder 1px solid;">
<tr>
<td style="width: 200px; height: 15px" align="right">
<asp:Label ID="Label2" runat="server" Text="Ragione sociale"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXRagioneSociale" runat="server" Width="296px"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TXRagioneSociale"
Display="Dynamic" ErrorMessage="Ragione sociale richiesta"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
<asp:Label ID="Label3" runat="server" Text="Sede legale"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXSedeLegale" runat="server" Width="296px"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TXSedeLegale"
Display="Dynamic" ErrorMessage="Indirizzo sede legale richiesto"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
<asp:Label ID="Label4" runat="server" Text="C.A.P."></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXCap" runat="server" Width="80px"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TXCap"
Display="Dynamic" ErrorMessage="Codice di avviamento postale richiesto"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
<asp:Label ID="Label5" runat="server" Text="Provincia"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="ProvinciaDataSource"
DataTextField="NomeProvincia" DataValueField="IDProvincia">
<asp:ListItem Selected="True">Selezionare una provincia</asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource ID="ProvinciaDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData" TypeName="DataSet1TableAdapters.ProvinciaTableAdapter"></asp:ObjectDataSource>
</td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
</td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
<asp:Label ID="Label6" runat="server" Text="Comune"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="ComuneDataSource"
DataTextField="Comune" DataValueField="IDComune">
</asp:DropDownList>
<asp:ObjectDataSource ID="ComuneDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData" TypeName="DataSet1TableAdapters.ComuneTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="IDProvincia" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
</td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
<asp:Label ID="Label7" runat="server" Text="Partita IVA"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXPartitaIva" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TXPartitaIva"
Display="Dynamic" ErrorMessage="La partita IVA è incorretta" SetFocusOnError="True"
ValidationExpression="\d{11}"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
<asp:Label ID="Label8" runat="server" Text="Telefono"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXTelefono" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TXTelefono"
ErrorMessage="Il numero di telefono è richiesto"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
<asp:Label ID="Label9" runat="server" Text="Fax"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXFax" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
</td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
<asp:Label ID="Label10" runat="server" Text="Cellulare"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXCellulare" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
</td>
<td align="left" colspan="2" style="height: 15px">
</td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
<asp:Label ID="Label11" runat="server" Text="E-mail"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXEmail" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TXEmail"
EnableViewState="False" ErrorMessage="L'indirizzo E-mail inserito non è corretto"
SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@.\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td align="left" colspan="3" style="height: 15px; background-color: buttonface">
<asp:Label ID="Label12" runat="server" Text="Luogo di scarico (non obbligatorio)"></asp:Label></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
<asp:Label ID="Label13" runat="server" Text="Indirizzo"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXIndirizzoScarico" runat="server" Width="296px"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
</td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
<asp:Label ID="Label14" runat="server" Text="Provincia"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True" DataSourceID="ProvinciaDataSource"
DataTextField="NomeProvincia" DataValueField="IDProvincia">
<asp:ListItem Selected="True">Selezionare una provincia</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
</td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
<asp:Label ID="Label15" runat="server" Text="Comune"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="True" DataSourceID="ComuneScaricoDataSource"
DataTextField="Comune" DataValueField="IDComune">
<asp:ListItem Selected="True">Selezionare una provincia</asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource ID="ComuneScaricoDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData" TypeName="DataSet1TableAdapters.ComuneTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList3" Name="IDProvincia" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
<asp:Label ID="Label18" runat="server" Text="C.A.P."></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXCapScarico" runat="server" Width="80px"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
</td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
<asp:Label ID="Label16" runat="server" Text="Telefono"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXTelefonoScarico" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
</td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
<asp:Label ID="Label17" runat="server" Text="Fax"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXFaxScarico" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
</td>
<td align="left" colspan="2" style="height: 15px">
</td>
</tr>
<tr>
<td align="right" style="width: 200px; height: 15px">
<asp:Label ID="LabelCodiceCliente" runat="server" Text="Codice cliente" Visible="False"></asp:Label></td>
<td align="left" colspan="2" style="height: 15px">
<asp:TextBox ID="TXCodiceCliente" runat="server" Visible="False"></asp:TextBox></td>
</tr>
<tr>
<td align="left" colspan="3" style="height: 15px">
</td>
</tr>
<tr>
<td style="width: 200px; height: 15px" align="right">
</td>
<td style="width: 200px; height: 15px">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="StartInsert();"
Text="Inserisci cliente" /></td>
<td style="width: 200px; height: 15px">
</td>
</tr>
</table>
</ContentTemplate>
</atlas:UpdatePanel>

<atlas:UpdateProgress ID="updateProgress1" runat="server">
<ProgressTemplate>
<table style="position: absolute; top: 100px; left: 50%; margin: 0px -100px; z-index: 4;
border-right: appworkspace thin solid; border-top: appworkspace thin solid; border-left: appworkspace thin solid;
border-bottom: appworkspace thin solid; background-color: inactivecaptiontext;
width: 200px;">
<tr>
<td style="font-family: Verdana; font-weight: bold; font-size: 10px; color: maroon;">
<img alt="" src="http://pics.10026.com/?src=images/spinner.gif" />
Contacting Server...
<button id="abortButton">
Stop</button>
</td>
</tr>
</table>
</ProgressTemplate>
</atlas:UpdateProgress>
</td>
</tr>
</table>
</asp:Content>


hiya,

I think using the Atlas UpdateProgress thing "which comes with Jan release" would help. Try to use it

Thanks,


I am using Jenuary release.

if I see the page with IE7 that is very nice, no refresh but with ie6 is very bad.


What's the purpose of the following line from your code? Doesn't this force 3 seconds of pause that you've mentioned?

System.Threading.Thread.Sleep(3000)

Ciao,

I use the System.Threading.Thread.Sleep(3000) just to simulate the insert into database.