using VS 2010, C#, asp.net
I have timer control in my master page and I want to access it from my master page .cs file
But it didn't work, even when I used this code
((System.Web.UI.Timer)this.FindControl("Timer1")).Enable = false;
it look like VS don't know what is tiemr control ?!!!
please advice,
my first try was just,
Timer1.Enable=false;
and it didn't work and got this in when I run the web
"Compiler Error Message: CS1061: 'System.Web.UI.Timer' does not contain a definition for 'Enable' and no extension method 'Enable' accepting a first argument of type 'System.Web.UI.Timer' could be found (are you missing a using directive or an assembly reference?)"
here is my asp.net code
<%# Master Language="C#" AutoEventWireup="true" CodeFile="Ads_master.master.cs" Inherits="Ads_master" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head1" runat="server">
<title>Every200</title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.style1
{
width: 22%;
}
.style2
{
width: 263px;
}
.style3
{
width: 49px;
}
</style>
</head>
<body>
<form id="Form1" runat="server">
<div class="page">
<div class="header">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="title">
<h1 style="font-family: Tahoma">
EVERY200.com
</h1>
<p style="color: #FFFF66; font-weight: 700; font-family: Tahoma;"> stop hunt cents, start hunt dollars</p>
</div>
<div class="loginDisplay">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<table class="style1">
<tr>
<td class="style2">
</td>
<td class="style2">
</td>
<td class="style2">
<asp:Label ID="Label_counter" runat="server" Font-Bold="True"
Font-Size="XX-Large" Text="0"></asp:Label>
<asp:Label ID="Label_message" runat="server" Font-Bold="True"
Font-Size="Medium"></asp:Label>
<asp:Label ID="AdsCaptchaHolder" runat="server" Visible="False"></asp:Label>
</td>
<td class="style3" style="text-align: left">
</td>
<td class="style3" style="text-align: left">
<asp:Button ID="Button_verify" runat="server" BackColor="#0033CC"
BorderStyle="Solid" Height="100%" onclick="Button1_Click" Text="Verify"
Visible="False" Width="100%" />
</td>
<td class="style3" style="text-align: left">
</td>
<td>
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="http://images.neobux.com/imagens/banner5.gif"
PostBackUrl="http://www.neobux.com/?r=amrosama77" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="10000" ontick="Timer1_Tick">
</asp:Timer>
</div>
<div class="clear hideSkiplink">
</div>
</div>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer" align="left">
</div>
</form>
</body>
</html>
try this,
Timer tm = Master.FindControl("Timer1") as Timer;tm.Enabled = false;
If you have added timer control in Master Page file, you can access timer control directly in Masterpage code behind file.
Please refer below code:
<asp:ScriptManager runat="server">
</asp:ScriptManager>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
<asp:Timer runat="server" id="Timer1">
</asp:Timer>
</asp:ContentPlaceHolder>
Code behind file :(.cs file)
Timer1.Enabled = false;
Please check if you have added the ScriptManager code.
Hi,
Please try this code and check.
((Timer)this.FindControl("timer1")).Enabled = false;
Related
I'm trying to figure out how to center this table without taking into account the third column, which is for data validation. I have it rendering exactly how I want it now with the display none attributes on the third column but then my error text won't show. What is the simplest way to go about this? Thanks!
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="budgetTracker.Login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="content/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="content/custom.css" />
</head>
<body>
<form id="form1" runat="server">
<div class="container center">
<div class="center">
<div class="vert">
<table style="margin-left: auto; margin-right: auto;">
<tr>
<td colspan="2">
<h1>Budget Tracker Login</h1>
</td>
</tr>
<tr>
<td>
<asp:Label ID="userNamelbl" runat="server" Text="User Name"></asp:Label></td>
<td>
<asp:TextBox ID="userNameBox" class="form-control" runat="server"></asp:TextBox></td>
<td style="display: none;">
<asp:RequiredFieldValidator ID="userNameRequired" runat="server" ErrorMessage="Username is Required" ControlToValidate="userNameBox" ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>
<asp:Label ID="passwordlbl" runat="server" Text="Password"></asp:Label></td>
<td>
<asp:TextBox ID="passwordBox" class="form-control" runat="server" TextMode="Password"></asp:TextBox></td>
<td style="display: none;">
<asp:RequiredFieldValidator ID="passwordRequired" runat="server" ErrorMessage="Password is Required" ControlToValidate="passwordBox" ForeColor="Red"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button1" runat="server" class="btn btn-primary btn-space" Text="Login" OnClick="loginButton_Click" /></td>
</tr>
<tr>
<td colspan="2">Not yet a member? Click HERE to register!</td>
</tr>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
Marco is right, table should be used for tabular data not for layout.
To answer your question, you can remove the "display: none;" in your td tag.
Add a label control for your error message (I'd call it "ErrorLabel") then add this code on in your "error area" (that would be inside your loginButton_Click method)
ErrorLabel.Visible = true;
In your PageLoad, add this:
if (!IsPostBack){
ErrorLabel.Visible = false;
}
I am a new one to ASP.NET and currently learning from the book "Beginning ASP.NET with Visual Studio 2015" by William Penberthy. In the chapter 7 about layout with master pages I created a custom master page WebForms with stylesheet RentMyWrox and moved the inline style for various controls of the page ManagedItems.aspx to RentMyWrox.css. This cause the layout to mess up.
When I switched back to default master page and added the inline style to default Site.css stylesheet the layout was displayed correctly. I downloaded the source code for the book and it has the same issue. Could anyone explain, what is the problem?
My custom master page WebForms.Master
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="WebForms.master.cs"
Inherits="RentMyWrox.WebForms" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link href="Content/RentMyWrox.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div id="header">
</div>
<div id="nav">
Navigation content here
</div>
<div id="section">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="footer">
Footer content here
</div>
</form>
</body>
</html>
Stylesheet for custom master page RentMyWrox.css
body {
font-family: verdana;
}
#header {
background-color:#C40D42;
color:white;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:750px;
float:left;
padding:10px;
}
#footer {
background-color:#C40D42;
color:white;
clear:both;
text-align:center;
padding:5px;
}
.dataentry input{
width: 250px;
margin-left: 20px;
margin-top: 15px;
}
.dataentry textarea{
width: 250px;
margin-left: 20px;
margin-top: 15px;
}
.dataentry label{
width: 75px;
margin-left: 20px;
margin-top: 15px;
}
#fuPicture {
margin-top: -20px;
margin-left: 120px;
}
Page ManagedItems.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/WebForms.Master" AutoEventWireup="true" CodeBehind="ManageItem.aspx.cs" Inherits="RentMyWrox.Admin.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
<div class="dataentry">
<asp:Label ID="Label1" runat="server" Text="Name"
AssociatedControlID="tbName"></asp:Label>
<asp:TextBox ID="tbName" runat="server"></asp:TextBox>
</div>
<div class="dataentry">
<asp:Label ID="Label2" runat="server" Text="Description"
AssociatedControlID="tbDescription"></asp:Label>
<asp:TextBox ID="tbDescription" runat="server"
TextMode="MultiLine" Rows="5"></asp:TextBox>
</div>
<div class="dataentry">
<asp:Label ID="Label3" runat="server" Text="Cost"
AssociatedControlID="tbCost"></asp:Label>
<asp:TextBox ID="tbCost" runat="server"></asp:TextBox>
</div>
<div class="dataentry">
<asp:Label runat="server" Text="Item Number" AssociatedControlID="tbItemNumber"/>
<asp:TextBox runat="server" ID="tbItemNumber" /> </div> <div class="dataentry">
<asp:Label runat="server" Text="Picture" AssociatedControlID="fuPicture" />
<asp:FileUpload ID="fuPicture" ClientIDMode="Static" runat="server" />
</div>
<div class="dataentry">
<asp:Label runat="server" Text="Acquired Date" AssociatedControlID="tbAcquiredDate"/>
<asp:TextBox runat="server" ID="tbAcquiredDate"/>
</div>
<asp:Button Text="Save Item" runat="server" OnClick="SaveItem_Click" />
</div>
</asp:Content>
This is how it should look according to the book
This is how it actually looks like
The source code can be downloaded at http://media.wiley.com/product_ancillary/27/11190774/DOWNLOAD/RentMyWrox_Chapter7_CSharp..zip
Is the code attached/linked the "before" or "after" modification code?
My recommendation is to use the tools of your browser to check if the CSS file was actually loaded. In Chrome, you can press F12 and then click on the "Sources" tab. This will show you what is loaded down the left, I'm guessing your CSS file is not there.
If that's the case, it might be your reference in your master file.
Currently you have it as:
But that link is not a valid link from your manageitem.aspx page which is inside the 'Admin' folder.
Instead, try "~/Content/RentMyWrox.css" - this should map the proper path from the root of your application, rather than relative to whichever child page is loading the master.
i'm facing a problem, currently i'm having a update panel in my master page and in one of my child page i'm having a asp fileupload control.
My update Panel in master p[age:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:updateprogress associatedupdatepanelid="UpdatePanel1"
id="updateProgress" runat="server">
<progresstemplate>
<div id="processMessage" style=" background-image:url('../../Styles/ajax-loader3.gif'); width:100px; height:100px; background-repeat:no-repeat; background-position:center;">
</div>
</progresstemplate>
</asp:updateprogress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
..
</ContentTemplate>
</asp:UpdatePanel>
</form>
My Child page which needs a fileupload:
<div id="Annoucments" class="ContentDIV">
<h2 class="Tabheader">Annoucments</h2>
<p class="tabdescription">Here you will be able to upload announcements and pictures to be displayed in the login page, below is the current announcement click on update to save the changes that you have made.</p>
<table width = "100%">
<tr>
<td class="Tablabel">Annoucment title:</td> <td class="tableInput" align="left"><asp:TextBox ID="Announcement_TB" runat="server" CssClass="textboxTabs"></asp:TextBox></td>
<td class="Tablabel">Picture/Poster:</td> <td class="tableInput" align="left"><asp:FileUpload ID="Announcement_PIC" runat="server" CssClass="textboxTabsFiles"/></td>
</tr>
<tr>
<td class="Tablabel">Description:</td> <td class="tableInput" align="left"><asp:TextBox ID="Announcement_Desc" CssClass="textboxTabs" runat="server" Rows="3" TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr><td colspan="4" style="height:10px" id ="BLANK">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td></tr>
<tr>
<td colspan="2" align="right"><input type="button" id="Announcement_Update" runat="server" value="Update" class="TabButton" onserverclick="ANNOUNCEMENT_UPDATE_Click" style=" font-size:smaller"/></td><td colspan="2"> <input type="button" ID="ANNOUNCEMENT_Cancel" runat="server" value="Cancel" class="TabButton" style=" font-size:smaller"/></td>
</tr>
</table>
</div>
*When i click the button Announcement_Update backend codes will be triggered to get my filename, the file name returned will always be "" found out while debugging.*
Put this code in child page, to pass PostBackTrigger for file upload.
protected void Page_Load(object sender, EventArgs e)
{
UpdatePanel updatePanel = Page.Master.FindControl("UpdatePanel1") as UpdatePanel;
UpdatePanelControlTrigger trigger = new PostBackTrigger();
trigger.ControlID = Announcement_Update.UniqueID;
updatePanel.Triggers.Add(trigger);
}
enjoy coding :)
You can't get filename inside that UpdatePanel
either remove that UpdatePanel from your code or use Asynchronous File Uploader,
Alternatively you could use Ajax File Uploading techniques this is a little tricky though.
Asp UpdatePanel not work inside a update panel duw to postback issue.
You can add trigger with the button assosiated with uploader like
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
It works for me if you add the Trigger, but also make sure to edit to form tag to include:
<form runat="server" enctype="multipart/form-data">
I'm working on employee web application project, in my application i used the 2 update panels,hidden fields and buttons. actually what I'm doing is while clicking button i need to get next employee info and save it this info. and here whenever I'll click on button which in update panel2, get employee info and I'll keep this employee id into hidden field which in update panel1 and while debugging hidden field value shows correct employee id but saving time its having old value. for this I'm facing lot problem please help me.
Thank you
Here is my code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="border-left: 1px solid #CDCDCD; border-right: 1px solid #CDCDCD; background-color: #E9E9E9">
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true"
AsyncPostBackTimeout="36000" />
<div>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="60000">
</asp:Timer>
</div>
<div align="left" style="width: 715px; background: #E9E9E9;">
<div style="margin: 0px 30px 0px 45px; line-height: 140%; border-bottom: 1px solid #E0E2E0;
padding: 10px 0px 15px 0px">
<asp:UpdatePanel ID="upNextChapter" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table width="100%">
<tr>
<td align="right">
<asp:HiddenField ID="hfEmpId" runat="server" Value="0" />
** Employee Info **
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="imgbtnNext" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
<div align="right" style="padding-right: 30px;">
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ImageButton ID="imgbtnNext" runat="server" OnClick="imgbtnNext_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
<div align="center">
</div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Code behind:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void imgbtnNext_Click(object sender, EventArgs e)
{
//Get Employee Info & store it in Hidden field value=Employee Id
//** Saving Employee Info using Hidden filed value **
}
}
I did a similar test on my machine, I really can't see why HiddenField is not updated. Its most likely your "Get Employee Info" is the root cause.
Also I want to correct your code a bit.
Your first UpdatePanel is doing unnecessary task, the tag UpdateMode="Conditional" is no need.
Also
<Triggers>
<asp:AsyncPostBackTrigger ControlID="imgbtnNext" EventName="Click" />
</Triggers>
this tag has no effect to anything because the button is not in the current UpdatePanel. By default everything in UpdatePanel is AsyncPostBackTrigger anyway, unless you have something to post back you can add asp:PostBackTrigger.
I am pretty new to ASP.NET. I need to create a show/hide panel in ASP.NET that holds only text. The panel needs to have sliding effect. I can do with with postback. Is there any built-in control that can do this without postback.
Also, the text "Show" should change to "Hide" without postback.
EDIT: Forgot to mention that I have several such panels in my application.
The ASP.Net Ajax Control Toolkit has the accordian control that has customizable themes and effets, the whole library is well worth a look at.
Have you looked into jQuery?
http://api.jquery.com/toggle/
you can try like this....
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function Show1_onclick() {
document.getElementById('Panel1').style.display ='block';
document.getElementById('Panel2').style.display ='none';
document.getElementById('Hidden1').value = 'Panel1';
}
function Show2_onclick() {
document.getElementById('Panel1').style.display ='none';
document.getElementById('Panel2').style.display ='block';
document.getElementById('Hidden1').value = 'Panel2';
}
function StartUpScript()
{
if (document.getElementById('Hidden1').value == 'Panel1')
{
document.getElementById('Panel1').style.display ='block';
document.getElementById('Panel2').style.display ='none';
}
else if (document.getElementById('Hidden1').value == 'Panel2')
{
document.getElementById('Panel1').style.display ='none';
document.getElementById('Panel2').style.display ='block';
}
}
// -->
</script>
</head>
<body onload="StartUpScript()">
<form id="form1" runat="server">
<div>
<input id="Show1" language="javascript" onclick="return Show1_onclick()" type="button"
value="Show1" />
<input id="Show2" language="javascript" onclick="return Show2_onclick()" type="button"
value="Show2" />
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
<table id="Table1">
<tr>
<td style="width: 95px">
table1<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click1" />
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px">
<table id="Table2">
<tr>
<td style="width: 99px">
table2<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Click2" />
</td>
</tr>
</table>
</asp:Panel>
<input id="Hidden1" runat="server" type="hidden" />
</div>
</form>
</body>
</html>