UpdatePanel reset textbox background color - asp.net

I have an UpdatePanel within it a textbox with a background color of yellow and a trigger for text-changed for the textbox and everything works fine except that the background color reverts to white when I write some text in the text box and then focus somewhere else.
What is causing this? Thanks.
Using asp.net 4.0
Here is the asp.net markup:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<span>
<asp:TextBox ID="sticky" runat="server" AutoPostBack="true"
Text='<%# Bind("sticky") %>' TextMode="MultiLine"
OnTextChanged="cSticky" />
</span>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="sticky" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
Here is the css:
#StickyDiv textarea
{
height:170px;
width:185px;
resize:none;
margin-top:1px;
border:none;
font-family:Comic Sans MS;
font-size:1.2em;
padding:3px;
line-height:1.1em;
}
And here is the jQuery:
$(function () {
$("#StickyDiv textarea:even").css("background-color","#ffff95");
$("#StickyDiv textarea:odd").css("background-color", "#fe8ab9");
});

Your problem is that when you do a update in the ajax panel your jquery is not called. If the text is changed you update the box to yellow and not call the javascript because it is rendered outside of your panel. To fix this you can register the script in you codebehide like:
ScriptManager.RegisterClientScriptBlock(Page,typeof(string),"JavaScriptCall",script.ToString(), false);

I did in the folowing example
in ASPX file
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" BackColor="Yellow" AutoPostBack="true" OnTextChanged="textChanged"></asp:TextBox>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
In Codebehind File
protected void textChanged(object sender, EventArgs e)
{
TextBox1.BackColor = System.Drawing.Color.Yellow;
Label1.Text = TextBox1.Text;
}

Related

Add UserControl Dynamically in Panel Control asp.net page

I am creating a website where user gives some value in textbox and clicks a button.
On the button click the UserControl should be added for number of time the user has given input.
What I did is,
protected void btnSearchTaxi_Click(object sender, EventArgs e)
{
for (int i = 0; i < 4; i++)
{
CustomDisplayList cus = new CustomDisplayList();
cus.ID = "cus" + i;
cus.Visible = true;
pnlSearchResult.Controls.Add(cus);
}
}
CustomDisplayList is my user control which is complex control [mixture of labels, textbox, button].
<td style="width:20%; font-family: Century Gothic; font-size:12px; color:White; text-
align:center;">Click to find<br/>
<asp:Button ID="btnSearchTaxi" runat="server" Text="Search Taxi" CssClass="googleButton"
Width="200px" onclick="btnSearchTaxi_Click" />
</td>
<td style="height:150px; width:100%; background-color: #FF6600">
<table style="height:100%; width:100%">
<tr><td style="color:White; font-size:30px; ">Search Result :</td></tr>
<tr><td><asp:Panel ID="pnlSearchResult" runat="server"></asp:Panel>
</td></tr>
</table>
</td>
The code was executed without any error, but the Control was not generated inside the panel.
Now I have changed the CODE to something like
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode = "Conditional" >
<ContentTemplate>
<asp:Button ID="btnSearchTaxi" runat="server" Text="Search Taxi" CssClass="googleButton" Width="200px" onclick="btnSearchTaxi_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode = "Conditional">
<ContentTemplate>
<asp:Panel ID="pnlSearchResult" runat="server" Width="100%" Height="200px" BackColor="Aquamarine"></asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID = "btnSearchTaxi" EventName="Click"/>
</Triggers>
</asp:UpdatePanel>
But the still the Dynamic usercontrol are not getting created.

could not be found for the trigger in UpdatePanel

I need to keep the button in usercontrol (.ascx) file. and i have given the AsyncPostBackTrigger controlid for the same button. but its showing "ERROR" like could not be found for the trigger in UpdatePanel. could any one help me?
this i have give controlid
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlYourAccount" runat="server" Style="display: none; height: 100%;
margin-left: 330px; margin-top: -230px;">
here is my design
</asp:Panel>
</<ContentTemplate>
</asp:UpdatePanel>
`
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn1" EventName="Click" />
</Triggers>
`
this Linkbutton i have kept in user control(for Top menu). while click on the menu the content should get update
<asp:LinkButton class="anchorstyle" ID="btn1" runat="server" Text="MenuName" />
in aspx page
<asp:LinkButton class="anchorstyle" ID="btn1" runat="server" Text="MenuName" OnClick="btn1_Click" />
in aspx.cs page add this event
protected void btn1_Click(object sender, EventArgs e)
{
//write your code here
}
then its working properly.

How to get text in popup control extender?

i am using a popup control extender.but i am getting only index of selected value from radiobutton list.I want to get the text
Below is my source code
<div class="FloatRight">
<asp:TextBox ID="txtTeam" runat="server" Width="150px" autocomplete="off"></asp:TextBox>
<br />
<asp:Panel ID="panel" runat="server">
<div style="border: 1px outset white; width: 100px">
<asp:UpdatePanel runat="server" ID="up1">
<ContentTemplate>
<asp:RadioButtonList ID="rbteam" runat="server" AutoPostBack="true" OnSelectedIndexChanged="rbteam_SelectedIndexChanged">
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Panel>
<cc1:PopupControlExtender ID="txtTeam_PopupControlExtender" runat="server" Enabled="True"
and this is server side
protected void rbteam_SelectedIndexChanged(object sender, EventArgs e) {
if (!string.IsNullOrEmpty(rbteam.SelectedValue))
{
txtTeam_PopupControlExtender.Commit(rbteam.SelectedValue);
}
else
{
txtTeam_PopupControlExtender.Cancel();
}
rbteam.ClearSelection();
}
txtTeam_PopupControlExtender.Commit(rbteam.SelectedItem.Text);

Specify when UpdateProgress Control are displayed

Does anyone have a resource or provide a code sample on when not to display an UpdatePrgress Control when a certain button is clicked.
in your Markup:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel</legend>
<asp:Label ID="Label1" runat="server" Text="Initial page rendered."></asp:Label><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
Processing...
</ProgressTemplate>
</asp:UpdateProgress>
in your code behind:
protected void Button1_Click(object sender, EventArgs e)
{
// Introducing delay for demonstration.
System.Threading.Thread.Sleep(3000);
Label1.Text = "Page refreshed at " +
DateTime.Now.ToString();
}
this should work, try it...
source: Introduction to the UpdateProgress Control

confused about update panel

In my form I have a label and button control.
By default the label is visible. When a user clicks on the button I have made the label to visible false.
For simple button it is working, but when I add an updatePanel to button the event is getting fired but the label is not getting to visible false. Just try this, and please can anybody tell me why this is happening and the solution for this.
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:fileupload ID="Fileupload1" runat="server"></asp:fileupload>
<asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label>
<asp:UpdatePanel ID="up" runat ="server" >
<ContentTemplate >
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("hello");
Label1.Visible = false;
}
From the looks of it you need to wrap your label within the update panel as well.
Try
<asp:fileupload ID="Fileupload1" runat="server"></asp:fileupload>
<asp:UpdatePanel ID="up" runat ="server" >
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
An update panel will update a section of your page. Your label wasn't included within the updatepanel so would never get updated with your new value.
I suggest that you only wrap the label with the UpdatePanel and set the UpdateMode to "Conditional".
<asp:UpdatePanel ID="up" runat ="server" UpdateMode="Coditional" >
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
Regards.

Resources