I have a TextArea control in my content page which is inside an UpdatePanel:
<asp:UpdatePanel runat="server" ClientIDMode="Static" ID="upTaskDetailRight" UpdateMode="Conditional">
<ContentTemplate>
<div style="width: 98%; padding-bottom: 10px;" class="brClear">
<div style="width: 98%; height: 120px;">
<textarea id="taskNotes" runat="server" class="taskNotes" style="width: 100%; height: 100%; scrollbar-base-color: #A0A0A0; scrollbar-base-color: #A0A0A0; scrollbar-3dlight-color: #A0A0A0; scrollbar-highlight-color: #A0A0A0; scrollbar-track-color: #EBEBEB; scrollbar-arrow-color: #FFFFFF; scrollbar-shadow-color: #A0A0A0; scrollbar-darkshadow-color: #A0A0A0;"></textarea>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I have a button in my MasterPage which is accessing the TextArea value from the content page and updating the SQL Database:
<asp:Panel ID="Panel93" runat="server" CssClass="navInnerDivContentsTopSubTwo">
<asp:ImageButton ID="ibSave" ImageUrl="~/theImages/Save.png" runat="server" CssClass="navImages" OnClick="btnSave_Click" />
<br />
<asp:LinkButton ID="btnSave" runat="server" Text="Save" ClientIDMode="Static" OnClick="btnSave_Click" CssClass="linkOff" />
</asp:Panel>
Code-behind:
System.Web.UI.HtmlControls.HtmlTextArea lblTDNotes;
lblTDNotes = (System.Web.UI.HtmlControls.HtmlTextArea)ContentMain.FindControl("taskNotes");
protected void btnSave_Click(object sender, EventArgs e)
{
string strSaveQuery = #"UPDATE HSI.RMMEMO SET MEMO = '" + lblTDNotes.Value + "' WHERE MEMOID = '" + hfMemoIDYT.Value + "'";
//MessageBox.Show(strSaveQuery);
using (SqlConnection scConn = new SqlConnection(strMainConn))
{
try
{
scConn.Open();
SqlCommand cmd = new SqlCommand(strSaveQuery, scConn);
cmd.ExecuteNonQuery();
Response.Redirect("YourTasks.aspx");
}
catch (Exception ce)
{
}
}
}
When the page loads, the TextArea has some pre populated data. If I make any changes to the TextArea data (add or remove text) and hit the SAVE button in the Master page, the lblTDNoted.Value from the strSaveQuery is using the pre populated data and not the updated entry.
How do I get the updated entry from the textarea?
Add <triggers> to your UpdatePanel.
<asp:UpdatePanel runat="server" ...>
<ContentTemplate>
...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Related
I want to make a button invisible when the timer on my page is up. The timer on my page is set to be up in 1 minute. Once the timer is up, I want to set the button visible=false, but the button does not become invisible.
Below is the code for the timer:
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="1000" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
<div class="sticky">
<span style="border: 2px; color: red; font-size: 25px;">Time Remaining: <asp:Label ID="Label2" runat="server"></asp:Label></span>
<br />
</ContentTemplate>
</asp:UpdatePanel>
below is the button on the page:
<asp:Button ID="btnTest" runat="server" Text="Test" OnClick="test_click" />
My aspx.cs code is like so:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SendBulkEmail
{
public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["CountdownTimer"] == null)
{
Session["CountdownTimer"] = new TimeSpan(0, 1, 0);
}
TimeSpan current = (TimeSpan)Session["CountdownTimer"];
Label1.Text = current.ToString("%m") + " minutes and " + current.ToString("%s") + " seconds";
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
TimeSpan ts2sec = new TimeSpan(0, 0, 2); // 2 seconds
TimeSpan ts = (TimeSpan)Session["CountdownTimer"]; // current remaining time from Session
TimeSpan current = ts - ts2sec; // Subtract 5 seconds
Label1.Text = current.ToString("%m") + " minutes and " + current.ToString("%s") + " seconds";
Session["CountdownTimer"] = current; // put new remaining time in Session
if (current.Seconds == 0 && current.Minutes == 0)
{
Session["CountdownTimer"] = "";
Timer1.Enabled = false;
Label1.Text = "Your Session is timed out. ";
btnTest.Visible = false;
}
}
protected void test_click(object sender, EventArgs e)
{
string a = "This is Test";
}
}
}
I am setting the btnTest.Visible = false; in my Timer_tick event when the time is up, but the btnTest does not become invisible. Below is the entire code for .cs code-behind page:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="SendBulkEmail.WebForm4" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="src1" runat="server"></asp:ScriptManager>
<div>
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="1000" />
<asp:UpdatePanel ID="StockPricePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
<div class="sticky">
<span style="border: 2px; color: red; font-size: 25px;">Time Remaining: <asp:Label ID="Label1" runat="server"></asp:Label></span>
<br />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div>
<asp:Button ID="btnTest" runat="server" Text="Test" OnClick="test_click" />
</div>
</form>
</body>
</html>
Any help will be highly appreciated.
Your button is not in the UpdatePanel - your code is setting btnTest.Visible = false, but is not updating the page. The current page state becomes invalid (clicking the button will fail), but no visible update happens. Move your button code into the UpdatePanel, as follows:
<asp:UpdatePanel ID="StockPricePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
<div class="sticky">
<span style="border: 2px; color: red; font-size: 25px;">Time Remaining: <asp:Label ID="Label1" runat="server"></asp:Label></span>
<br />
<div>
<asp:Button ID="btnTest" runat="server" Text="Test" OnClick="test_click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
Additionally, as TimeSpan can go negative, I recommend updating your check in Timer1_Tick event handler, as follows:
if (current.TotalMilliseconds <= 0)
{
Session["CountdownTimer"] = "";
Timer1.Enabled = false;
Label1.Text = "Your Session is timed out. ";
btnTest.Visible = false;
}
This will prevent any issues with not perfectly divisible values such as decrement of 7 seconds at a time instead of 2.
This is my rating control in aspx page. When user click the star, i want to update the label3.
<style type="text/css">
.Star {
background-image: url(img/Star.gif);
height: 17px;
width: 17px;
}
.WaitingStar {
background-image: url(img/WaitingStar.gif);
height: 17px;
width: 17px;
}
.FilledStar {
background-image: url(img/FilledStar.gif);
height: 17px;
width: 17px;
}
</style>
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<ajaxToolkit:Rating ID="Rating1" AutoPostBack="true" OnChanged="OnRatingChanged" runat="server"
StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star" CurrentRating="2"
FilledStarCssClass="FilledStar">
</ajaxToolkit:Rating>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Label runat="server" ID="label3"></asp:Label>
<asp:Label runat="server" ID="label4" Text="above"></asp:Label>
</div>
I tried out using Rating1.CurrentRating.ToString() but there is nothing on Label3.
protected void OnRatingChanged(object sender, RatingEventArgs e)
{
label3.Text = Rating1.CurrentRating.ToString();
}
Is my code wrong or I can get the value in another way? I'm planning to get the value from backend because later I will add it into my database. Please help. Thank you.
I think what are you looking for is OnClick() not OnChange(), as when user click on Rate control and change it's rating value you want to get current value of Rate control and show it in a label, BTW you should do following below desc,
before doing anything think about the properties of UpdatePanel like UpdateMode and ChildrenAsTriggers that you can set them like UpdateMode="Always" ChildrenAsTriggers="true" for UpdatePanel1 if by setting them it still doesnt work do the below steps:
1- Firstly move that label controls into the ContentTemplate of UpdatePanel
2- Then handle Click() event of ajaxToolkit:Rating
3- At the end you must have something like in design mode:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<ajaxToolkit:Rating ID="Rating1" AutoPostBack="true" runat="server"
StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
FilledStarCssClass="FilledStar" OnChanged="OnRatingChanged" OnClick="Rating1_Click">
</ajaxToolkit:Rating>
<asp:Label runat="server" ID="label3"></asp:Label>
<asp:Label runat="server" ID="label4" Text="above"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
and the code behind for Rating1_Click:
protected void Rating1_Click(object sender, RatingEventArgs e)
{
label3.Text = Rating1.CurrentRating.ToString();
}
this works like a charm!!!.
I have a repeater which i am trying to load after the page has loaded and have stumbled across the PreRender event. I have everything set up but the content of the repeater is not showing - the weird thing is that when i inspect the html, the code is there, just not displaying in the browser.
<asp:updatepanel id="panel1" runat="server" updatemode="Conditional" onprerender="upUpdatePanel_PreRender">
<contenttemplate>
<asp:repeater runat="server" id="mainContentRptr" onitemdatabound="bindDepts">
<headertemplate>
<div id="products-tabs-content" class="row tab-content">
</headertemplate>
<itemtemplate>
<div class="tab-pane" id='<%# eval("dept_id") %>
'> <asp:repeater runat="server" id="prodRepeater" onitemcommand="itemToCart">
<headertemplate>
.... </headertemplate>
<itemtemplate>
.... <asp:repeater runat="server" id="condRptr">
<headertemplate>
.... </headertemplate>
<itemtemplate>
.... </itemtemplate>
<footertemplate></footertemplate>
</asp:repeater>
</itemtemplate>
<footertemplate>
</div>
</footertemplate>
</asp:repeater>
</div>
<!-- End .tab-pane -->
</itemtemplate>
<footertemplate>
</footertemplate>
</asp:repeater>
</contenttemplate>
</asp:updatepanel>
As you can see a few nested repeaters... i also have my UpdateProgress control
<asp:UpdateProgress id="updateProgress" runat="server" AssociatedUpdatePanelID="panel1">
<ProgressTemplate>
<div style="position: relative; text-align: center; height: 100%; width: 100%; background-color: white; opacity: 0.7;margin:0 auto">
<asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="images/loader.GIF" AlternateText="Loading ..." ToolTip="Loading ..." style="padding: 10px; position: relative; top: 45%;margin: 0 auto" />
<br/>
<span style="font-size: 16pt;font-weight: bold">Bulding your menu</span>
<br/>
<span>Please wait</span>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
and then the following to trigger the delayed load
<script language="javascript" type="text/javascript">
function pageLoad(sender, e) {
if (!e.get_isPartialLoad()) {
__doPostBack('<%= panel1.ClientID %>', 'aaaa');
}
}
</script>
and server side...
protected void upUpdatePanel_PreRender(object sender, EventArgs e)
{
if (Request["__EVENTTARGET"] == panel1.ClientID &&
Request.Form["__EVENTARGUMENT"] == "aaaa")
{
populateRepeaters(); //This has databind for each repeater
}
}
This works without the prerender but loading speeding will vary depending on data etc so i wanted to have it load after the page loaded.
Any help would be appreciated guys! :)
a repeater was sitting out of the updatepanel that controlled the visibility of everything above. it was populated in the prerender event but did not display. Ive moved it inside the panel and everyhting is now working
I have planed to implement two pops in asp.net page. The First popup perform when the page button Click, and the Second popup perform when the first popup button click.
But When I Implement this in code, i got fist popup only. Can't got the second popup open.
ASPX Code-
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.Background
{
background-color: Black;
filter: alpha(opacity=90);
opacity: 0.8;
}
.Popup
{
background-color: #FFFFFF;
border-width: 3px;
border-style: solid;
border-color: black;
padding-top: 10px;
padding-left: 10px;
width: 400px;
height: 350px;
}
.lbl
{
font-size: 16px;
font-style: italic;
font-weight: bold;
}
</style>
<script type="text/javascript">
function ShowModalPopup() {
$find("mp1").show();
return false;
}
function HideModalPopup() {
// alert("Yes");
$find("mp1").hide();
return false;
}
function ShowModalPopup1() {
$find("ModalPopupExtender1").show();
return false;
}
function HideModalPopup1() {
// alert("Yes");
$find("ModalPopupExtender1").hide();
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="btnPopup1" runat="server" Text="Fill Form in Popup" />
<!-- ModalPopupExtender -->
<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="btnPopup1"
BehaviorID="modalPopupBehavior" CancelControlID="btnHide" BackgroundCssClass="Background">
</cc1:ModalPopupExtender>
<asp:Panel ID="Panl1" runat="server" CssClass="Popup" align="center" Style="display: none">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txt" runat="server" />
<asp:Label ID="Label2" Text="RED" runat="server" ForeColor="red" />
<asp:Button ID="Button2" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<asp:CheckBox ID="CheckBox1" TextAlign="Left" Text="ssdd" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnPopup1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="btnHide" runat="server" Text="Hide Modal Popup" OnClientClick="return HideModalPopup()" />
<!-- ModalPopupExtender 2 -->
<asp:Button ID="btnPopup2" runat="server" Text="Fill Form in Popup" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Panel1"
TargetControlID="btnPopup2" BehaviorID="modalPopupBehavior" CancelControlID="btnHide1"
BackgroundCssClass="Background">
</cc1:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="Popup" align="center" Style="display: none">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" />
<asp:Label ID="Label1" Text="Blue" runat="server" ForeColor="Blue" />
<asp:Button ID="Button4" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<asp:CheckBox ID="CheckBox2" TextAlign="Left" Text="ssdd" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnPopup2" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="btnHide1" runat="server" Text="Hide Modal Popup" OnClientClick="return HideModalPopup1()" />
</asp:Panel>
<!-- ModalPopupExtender 2 -->
</asp:Panel>
<!-- ModalPopupExtender -->
</form>
</body>
C# Code -
protected void btnSubmit_Click(object sender, EventArgs e)
{
Label2.Text = "Blue";
}
protected void btnClose_Click(object sender, EventArgs e)
{
}
This link might be of good use to you.
http://aspdotnetcodebook.blogspot.com.au/2009/03/how-to-open-modalpopup-inside.html
Also to have a modal pop up over another modal popup you need to set the z-index otherwise there are chances that the 2nd popup might hide behind the 1st. The following are the links which explains the same.
How to show a modal pop up above other modal pop up
http://blogs.msdn.com/b/codejunkie/archive/2009/06/23/multiple-modal-popups-and-z-index.aspx
http://tiredblogger.wordpress.com/2008/07/24/layering-modal-popups-using-css-z-index/
http://forums.asp.net/p/1280547/2458840.aspx#2458840
Hope this helps.
Please take a look on below url.
http://www.codeproject.com/Articles/546817/ASP-NET-Popup-Control-Displaying-as-multiple-neste
I am working in C#.Net and Ajax Concepts. I am having 2 ModelPopup Extender in a page. I am also having 2 Buttons in that page. When i click the 1st Button 1 MP should be displayed and when i click the 2nd Button, 2nd MP should get displayed. This works fine for me for the first time. [i.e] When i click the 1st Button, 1st MP is displayed and When i click the 2nd Button, 2nd MP is displayed and once again if i click the 1st Button nothing happens.
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<ajaxToolKit:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="Button2">
</ajaxToolKit:ModalPopupExtender>
<asp:Button ID="Button2" ToolTip="Location" runat="server" Text="Location(+)"
OnClientClick="LocClick();" />
<asp:Panel ID="Panel1" runat="server" Style="display: block; width: 600px; overflow: scroll;
height: 440px;" BackColor="White">
<table>
<tr valign="top">
<td width="650">
<ct:ASTreeView ID="astvMyTree" runat="server" BasePath="~/Scripts/astreeview/" DataTableRootNodeValue="0"
BackColor="White" EnableRoot="false" EnableNodeSelection="true" EnableCheckbox="false"
EnableDragDrop="false" EnableTreeLines="true" EnableNodeIcon="false" EnableCustomizedNodeIcon="false"
EnableDebugMode="false" EnableContextMenuAdd="false" EnableParentNodeExpand="false"
EnableAjaxOnEditDelete="false" AutoPostBack="true" OnOnSelectedNodeChanged="astvMyTree_OnSelectedNodeChanged" />
</td>
<td>
<div id="divConsole" runat="server">
</div>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<ajaxToolKit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Panel2"
TargetControlID="Button1">
</ajaxToolKit:ModalPopupExtender>
<asp:Button ID="Button1" ToolTip="Product" runat="server" Text="Product(+)"
OnClientClick="ProdClick();" />
<asp:Panel ID="Panel2" runat="server" Style="display: block; width: 600px; overflow: scroll;
height: 440px;" BackColor="White">
<table>
<tr valign="top">
<td width="650">
<ct:ASTreeView ID="ASTreeView1" runat="server" BasePath="~/Scripts/astreeview/" DataTableRootNodeValue="0"
BackColor="White" EnableRoot="false" EnableNodeSelection="true" EnableCheckbox="false"
EnableDragDrop="false" EnableTreeLines="true" EnableNodeIcon="false" EnableCustomizedNodeIcon="false"
EnableDebugMode="false" EnableContextMenuAdd="false" EnableParentNodeExpand="false"
EnableAjaxOnEditDelete="false" AutoPostBack="true" OnOnSelectedNodeChanged="astvMyTree_OnSelectedNodeChanged" />
</td>
<td>
<div id="div4" runat="server">
</div>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
I am just changing the back color of buttons in LocClick as well as ProdClick.
<script type="text/javascript">
function LocClick() {
var location = document.getElementById("<%= Button2.ClientID %>");
location.style.background = '#72BD66';
var product = document.getElementById("<%= Button1.ClientID %>");
product.style.background = '#065581';
var lastYear = document.getElementById('<%=chkLastYear.ClientID%>');
lastYear.checked = false;
}
How to fix this...