Adding dynamic year to AbleCommerce (ASP) footer - ablecommerce

I am not an ASP coder at all. Just trying to helop a friend by adding dynamic copyright date to existing AbleCommerce footer. My current code causes no errors but also has no output:
StoreFooter.ascx
<asp:Literal runat="server" ID="thisYear"></asp:Literal>
StoreFooter.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
AdminLink.Visible = AbleContext.Current.User.IsAdmin;
MobileLinkPanel.Visible = Request.Browser.IsMobileDevice;
MobileStoreLink.NavigateUrl = NavigationHelper.GetMobileStoreUrl("~/Default.aspx?FSIntent=false");
int thisYearInt = LocaleHelper.LocalNow.Year;
thisYear.Text = thisYearInt.ToString();
}
Also tried setting date as DateTime.Now.Year. Can anyone see what I am missing? I also get no output if I assign a string to thisYear.Text.

Instead of Literal use Label control. Try
<asp:Label runat="server" ID="thisYear"></asp:Label>

Related

how to store a label control text into a textbox control value

i am trying to set the value of a textbox control in my aspx page as the value of a label text. I am using the following code but nothing happens. I have tried from the code behind file using c# and then I want to assign the textbox value to a session variable. If I just assign a string value like "Hello"it works, but otherwise nothing works.
protected void btnBook_Click(object sender, EventArgs e)
{
txtmtcid.Text = blbtest.Text;
Session["mtcid"] = txtmtcid.Text;
//Response.Redirect("booknow.aspx");
}
}
I also tried with Javascript, but no use:
var mtcid = parsedData.employeeCode;
document.getElementById('txtmtcid').value = mtcid;
The above js code works fine if I am assigning the value of mtcid to a label text, but not for the text box. please help.
You don't show things that could be messing this up.
and we can't see your markup used.
What does your page load event look like. Keep in mind that EVERY button click, post-back or ANY control on the page with a event code stub WILL RUN the page load event EVERY time. the page load event runs every time, and BEFORE your button click code runs.
So, if I have this markup:
<asp:Label ID="blbtest" runat="server" Text="zoo"></asp:Label>
<br />
<asp:TextBox ID="txtmtcid" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
<br />
And then code behind of this:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
txtmtcid.Text = blbtest.Text;
}
I then get this when I click on the button
So, we can see how the lable text is now copy to the text box.
You have to post more markup, and give futher detilas (such as some grid view, repeater or any other boatload of features that well explain your issue).
Note that you can double click on the button in the web forms designer to create a event click for the button. Its possible that no event code for the button exists, and your button click code and code behind never runs.
So this is the markup:
<asp:Label ID="blbtest" runat="server" ClientIDMode="Static">
</asp:Label>
<asp:Button ID="btnBook" runat="server" Text="Book Now"
CssClass="spaces-info__button" OnClick="btnBook_Click"/>
<asp:TextBox ID="txtmtcid" runat="server">
</asp:TextBox>
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!(Session["username"] == null))
{
string usn = Session["username"].ToString();
lblusn.Text = usn;
}
}
protected void btnBook_Click(object sender, EventArgs e)
{
txtmtcid.Text = blbtest.Text;
Session["mtcid"] = txtmtcid.Text;
Response.Redirect("booknow.aspx");
}
updated js:
$(function () {
//dom is ready
var request = new XMLHttpRequest;
var usn = document.getElementById('lblusn').innerHTML;
//var usn = "juhaina.ahmed";
console.log(usn);
request.open('GET', "URL" + usn + ""); //of course I have replaced
the URL here
request.onload = function () {
var response = request.response;
var parsedData = JSON.parse(response);
console.log(parsedData);
var nm = parsedData.fullName;
document.getElementById('lblfullnm').innerHTML = nm;
var mtcid = parsedData.employeeCode;
document.getElementById('blbtest').innerHTML = mtcid;
document.getElementById('txtmtcid').value =
document.getElementById('blbtest').innerHTML
};
request.send();
});
I am new to js, and asp.net, so trying to browse whatever possible and work things out here. The session variable value is just not getting passed to next page. Honestly, i dont need the textbox, I dont know if label text can be stored in session variables. If thats possible, then all I want to do is assign the blbtest label text to the session variable, but that also didnt work,but if I am hard coding it like:
Session["mtcid"]="D-11234"
this works and the value of session variable is passed.
hence I am trying now with textbox. Please let me know if theres a better approach to this.
If there is a way to avoid the use of the label and textbox and simply pass the session variable, Session["username"] from the code behind to the javascript, that would be great. how can I do it?

DropDownList AutoPostBack not hitting break point

The auto post back for my drop down list is not hitting the break point in the code behind. It appears that changing the value of the drop down list is not causing the post back at all.
<asp:DropDownList ID="RidingType" runat="server" CssClass="option" DataValueField="VarId" DataTextField="Name" AutoPostBack="true" OnSelectedIndexChanged="RidingType_SelectedIndexChanged"></asp:DropDownList>
I have tried both OnSelectedIndexChanged and OnTextChanged. I am doing something similar on a different page, where it does work as expected.
<asp:DropDownList CssClass="listBoxes" runat="server" ID="lstBrands" DataValueField="brand" DataTextField="brand" AutoPostBack="true" OnTextChanged="lstBrands_SelectedIndexChanged" Width="100%"></asp:DropDownList>
I've done everything I can to match up the surrounding environments. Any ideas as to why the first appears not to post back and the second works correctly?
Edit:
Here is an excerpt from the code behind the binding function
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
/* code to set up other drop down lists */
BindRidingType();
/* more of the same */
}
}
private void BindRidingType()
{
prams[3].Value = "Riding Type";
RidingType.DataSource = ReturnSelection(prams); //return DataTable from Database
RidingType.SelectedValue = DefaultValue("Riding Type"); //Finds default value for list
RidingType.DataBind();
}
Per suggestion I tried not setting a default value, but I saw no change.
Edit:
The event handler as requested
protected void RidingType_SelectedIndexChanged(object sender, EventArgs e)
{
throw new NotImplementedException();
}

(ModalPopupExtender) two components with the same id can't be added to the application

I have a user control which I add on a page whenever user click on button. Following is the code to add control.
protected void Page_Init(object sender, EventArgs e)
{
if (Session["ControlCount"] != null)
{
for (int i = 1; i <= (int)Session["ControlCount"]; i++)
{
Control myUserControl = LoadControl("~/Controls/MessageControl.ascx");
divMessageControl.Controls.Add(myUserControl);
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnExpand_Click(object sender, EventArgs e)
{
int count = 0;
if (Session["ControlCount"] != null)
{
count = Convert.ToInt32(Session["ControlCount"]);
}
Control myUserControl = (Control)Page.LoadControl("~/Controls/MessageControl.ascx");
divMessageControl.Controls.Add(myUserControl);
Session["ControlCount"] = count + 1;
}
This control has ModalPopupExtender popup. When I add 2nd control on page it throws an error internally which i can see in firebug. How to make this popup id unique?
<asp:ModalPopupExtender ID="mpeReply" BehaviorID="mpeReply" runat="server" TargetControlID="btnReply"
PopupControlID="pnlReply" BackgroundCssClass="ModalPopupBG1">
</asp:ModalPopupExtender>
Sys.InvalidOperationException: Sys.InvalidOperationException: Two
components with the same id 'mpeReply' can't be added to the
application.
I have found the solution to this problem, as much as a lot of people have said, the simple solution is that your HTML is not properly formed - there is either an extra or missing closing tag to an element. Make sure that all your tags are properly closed and the problem should go away - struggled all day with this one!
I used this code to fix my problem, notice the ScriptMode is set to "Release"
<AjaxControlToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="Release">
</AjaxControlToolkit:ToolkitScriptManager>
I see a similar answer from this link:
http://www.advancesharp.com/questions/17658/sys-invalidoperationexception-two-components-with-the-same-id-xxx-can-t-be-added-to-the-application
Remove BehaviorID property from extender
Similar issue here. The solution for me was to change the Script Manager from a shortcut close tag to the full close tag , after adding the ScriptMode="Release" attribute:
Change:
<asp:ScriptManager ID="ScriptManager1" ScriptMode="Release" runat="server" />
to:
<asp:ScriptManager ID="ScriptManager1" ScriptMode="Release" runat="server></asp:ScriptManager>

Calls to successive calls on repeater with XML datasource is not binding new data

I have the following Page_Load function...
protected void Page_Load(object sender, EventArgs e)
{
XmlDataSource1.Data = GetXmlFromFile(Request.QueryString["file"]);
XmlDataSource1.DataBind();
Repeater1.DataBind();
}
The page in which this Page_Load resides is called by a parent page. Each time this Page_Load gets called the value of "file" in the query string will be different. So each time I will be receiving the XML contents from a different file which are inserted into the XmlDataSource and then bound against by the Repeater. Getting the XML data from the file works great but when I bind against the repeater that only works the first time through Page_Load. Each time after that when this code is executed the same results from the first XML file are displayed in the repeater.
What am I missing here. How can I get the XML data to be bound against the repeater on each page load instead of just the first one?
Tried creating a new XmlDataSource on each load?
protected void Page_Load(object sender, EventArgs e)
{
XmlDataSource source = new XmlDataSource();
source.ID = "MyDS";
source.Data = GetXmlFromFile(Request.QueryString["file"]);
source.DataBind();
Repeater1.DataSource = source;
Repeater1.DataBind();
}
I tried to duplicate the problem with a simple implementation that follows your main concept.
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["file"] != null)
{
XmlDataSource XmlDataSource1 = new XmlDataSource();
XmlDataSource1.DataFile = "~/App_Data/" + Request.QueryString["file"];
Repeater1.DataSource = XmlDataSource1;
Repeater1.DataBind();
}
}
Markup:
<asp:Repeater runat="server" ID="Repeater1" DataSourceID="XmlDataSource1">
<ItemTemplate>
<asp:Label runat="server" ID="lbl" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:Repeater>
This works when I browse to "Default.aspx?file=West.xml" where west.xml is an xml file in my App_Data folder. When I enter another existing xml file in the query string, it performs as expected. It's quick n' dirty, but maybe it will give you some idea when comparing it against your existing code.
On further investigation turns out the problem is a caching flag which is set to default true on XmlDataSource's. Other data source types like SqlDataSource do not have this flag enabled.
This is more fully outlined in the following article http://geekswithblogs.net/ranganh/archive/2006/04/28/76638.aspx
Upon disabling the caching feature everything works as expected.

Select current date by default in ASP.Net Calendar control

Let's say I have an aspx page with this calendar control:
<asp:Calendar ID="Calendar1" runat="server" SelectedDate="" ></asp:Calendar>
Is there anything I can put in for SelectedDate to make it use the current date by default, without having to use the code-behind?
If you are already doing databinding:
<asp:Calendar ID="Calendar1" runat="server" SelectedDate="<%# DateTime.Today %>" />
Will do it. This does require that somewhere you are doing a Page.DataBind() call (or a databind call on a parent control). If you are not doing that and you absolutely do not want any codebehind on the page, then you'll have to create a usercontrol that contains a calendar control and sets its selecteddate.
DateTime.Now will not work, use DateTime.Today instead.
I was trying to make the calendar selects a date by default and highlights it for the user.
However, i tried using all the options above but i only managed to set the calendar's selected date.
protected void Page_Load(object sender, EventArgs e)
Calendar1.SelectedDate = DateTime.Today;
}
the previous code did NOT highlight the selection, although it set the SelectedDate to today.
However, to select and highlight the following code will work properly.
protected void Page_Load(object sender, EventArgs e)
{
DateTime today = DateTime.Today;
Calendar1.TodaysDate = today;
Calendar1.SelectedDate = Calendar1.TodaysDate;
}
check this link: http://msdn.microsoft.com/en-us/library/8k0f6h1h(v=VS.85).aspx
Two ways of doing it.
Late binding
<asp:Calendar ID="planning" runat="server" SelectedDate="<%# DateTime.Now %>"></asp:Calendar>
Code behind way (Page_Load solution)
protected void Page_Load(object sender, EventArgs e)
{
BindCalendar();
}
private void BindCalendar()
{
planning.SelectedDate = DateTime.Today;
}
Altough, I strongly recommend to do it from a BindMyStuff way. Single entry point easier to debug. But since you seems to know your game, you're all set.
I have tried above with above code but not working ,Here is solution to set current date selected in asp.net calendar control
dtpStartDate.SelectedDate = Convert.ToDateTime(DateTime.Now.Date);
dtpStartDate.VisibleDate = Convert.ToDateTime(DateTime.Now.ToString());
I too had the same problem in VWD 2010 and, by chance, I had two controls. One was available in code behind and one wasn't accessible. I thought that the order of statements in the controls was causing the issue. I put 'runat' before 'SelectedDate' and that seemed to fix it. When I put 'runat' after 'SelectedDate' it still worked!
Unfortunately, I now don't know why it didn't work and haven't got the original that didn't work.
These now all work:-
<asp:Calendar ID="calDateFrom" SelectedDate="08/02/2011" SelectionMode="Day" runat="server"></asp:Calendar>
<asp:Calendar runat="server" SelectionMode="Day" SelectedDate="08/15/2011 12:00:00 AM" ID="Calendar1" VisibleDate="08/03/2011 12:00:00 AM"></asp:Calendar>
<asp:Calendar SelectionMode="Day" SelectedDate="08/31/2011 12:00:00 AM" runat="server" ID="calDateTo"></asp:Calendar>
Actually, I cannot get selected date in aspx. Here is the way to set selected date in codes:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DateTime dt = DateTime.Now.AddDays(-1);
Calendar1.VisibleDate = dt;
Calendar1.SelectedDate = dt;
Calendar1.TodaysDate = dt;
...
}
}
In above example, I need to set the default selected date to yesterday. The key point is to set TodayDate. Otherwise, the selected calendar date is always today.

Resources