Default page code behind not working when published on hosting server - c#

I decided not to redirect a first visitor from default to my "Not Logged In" page and just turn default in the "Not Logged In" page. When i did this, none of the code is working in the codebehind except for the page load. I have a menu that works perfectly fine, but any link button, or login code in the master page is not working. Maybe it has to do with the url rewriting the hosting provider does? My page doesn't have default.aspx in the url it just shows www.mywebsite.com
Here is my page load on default.
if (!IsPostBack)
{
AbuseReport abuse = new AbuseReport();
abuse.Message = "page load clicked";
abuse.ReportingPersonID = 1;
abuse.AbuserPersonID = 1;
abuse.CreateAbuseReport();
SiteViews();
bool stayOnSite = (Session["StayOnMainSite"] != null && !Parser.GetBoolean(Session["StayOnMainSite"]));
string strUserAgent = Request.UserAgent.ToString().ToLower();
if (strUserAgent != null)
{
if (Request.Browser.IsMobileDevice == true || strUserAgent.Contains("iphone") ||
strUserAgent.Contains("blackberry") || strUserAgent.Contains("mobile") ||
strUserAgent.Contains("windows ce") || strUserAgent.Contains("opera mini") ||
strUserAgent.Contains("palm") || strUserAgent.Contains("android") ||
strUserAgent.Contains("ipad") || strUserAgent.Contains("moto") ||
strUserAgent.Contains("htc") || strUserAgent.Contains("sony") ||
strUserAgent.Contains("panasonic") || strUserAgent.Contains("midp") ||
strUserAgent.Contains("cldc") || strUserAgent.Contains("avant") ||
strUserAgent.Contains("windows ce") || strUserAgent.Contains("nokia") ||
strUserAgent.Contains("pda") || strUserAgent.Contains("hand") ||
strUserAgent.Contains("mobi") || strUserAgent.Contains("240x320") ||
strUserAgent.Contains("voda"))
{
if (!stayOnSite)
{
Response.Redirect("~/Mobile/Default.aspx");
return;
}
}
}
if (Session[ApplicationClass.UserSessions.AppUser] != null)
{
ApplicationClass appClass = ((ApplicationClass)Session[ApplicationClass.UserSessions.AppUser]);
if (appClass.User.IsPolitician)
{
UrlParameterPasser urlPasser = new UrlParameterPasser("~/PoliticianView/PoliticianWall.aspx");
urlPasser["PoliticianID"] = Parser.GetString(appClass.User.Politician.PoliticianID);
urlPasser.PassParameters();
}
else
{
Response.Redirect("~/User/UserMain.aspx");
}
}
}
Here is my login click (register is the same, and the abuse is just for logging purpose right now)
protected void lbtnLogin_Click(object sender, EventArgs e)
{
AbuseReport abuse = new AbuseReport();
abuse.Message = "Login clicked";
abuse.ReportingPersonID = 1;
abuse.AbuserPersonID = 1;
abuse.CreateAbuseReport();
Response.Redirect("~/Login/Login.aspx");
AbuseReport abuse2 = new AbuseReport();
abuse2.Message = "Login after click";
abuse2.ReportingPersonID = 1;
abuse2.AbuserPersonID = 1;
abuse2.CreateAbuseReport();
}
here is defualt.aspx
<%# Page Title="Politic Profiles Main" Language="C#" MasterPageFile="~/TwoColumn.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="PoliticProfiles._Default" %>
<table cellpadding="10px">
<tr>
<td>
<asp:Image ID="Image1" ImageUrl="~/Images/flags.jpg" AlternateText="American Flags"
runat="server" />
</td>
<td valign="top">
<h1>Welcome to Politic Profiles</h1>
<h2>Political information tailored to you.</h2>
<br />
<h3>
<asp:LinkButton ID="lbtnRegister" runat="server" Text="Register"
onclick="lbtnRegister_Click" />
<asp:Label ID="Label1" Text=" or " runat="server" />
<asp:LinkButton ID="lbtnLogin" runat="server" Text="Login"
onclick="lbtnLogin_Click"/>
<asp:Label ID="Label2" runat="server" Text=" to get the most out of your experience." />
</h3>
<ul class="landing">
<li>
<asp:Label ID="Label3" runat="server" Text="Ask your politicians questions." />
<br /><br />
</li>
<li>
<asp:Label ID="Label4" runat="server" Text="Keep up to date with what your politicians are doing." />
<br /><br />
</li>
<li>
<asp:Label ID="Label5" runat="server" Text="Allow your politicians to learn from you." />
<br /><br />
</li>
<li>
<asp:Label ID="Label6" runat="server" Text="Be involved in polls that help inform you politicians what track you want them on." />
<br /><br />
</li>
</ul>
</td>
</tr>
</table>
<uc:Polls id="ucPolls" runat="server" />
<br /><br />
<uc:Donate id="ucDonate" runat="server" />

Turned out to be because i had enableCrossAppRedirects="true"

Related

on using ajax, asp.net button control click event not working

I am using Ajax with asp.net C#. What I am trying to do is, on click of a link, a div should appear. A div contains file upload controls and a button named 'Upload Files'. When upload files button is clicked, it is checking if any of the file upload controls has files. If yes, it uploads files to some directory and updates a label to show how many files are uploaded 0 or more. Here is the screenshot to explain:
Here's the code snippet, I am using Ajax with asp.net C#
<div class="form-group row">
<asp:UpdatePanel runat="server" id="UpdatePanel1" updatemode="Conditional">
<ContentTemplate>
<div class="col-xs-5">
<% if (Session["MemberID"]!= null)
{%>
<asp:LinkButton ID="insertMore" runat="server" OnClick="insertMoreclicked">(Insert More Attachments)</asp:LinkButton>
<%} %>
</div><br />
<div id="moreUploadsDiv" runat="server" visible="false">
<br />
<asp:FileUpload ID="moreUpload1" runat="server" />
<asp:FileUpload ID="moreUpload2" runat="server" />
<asp:FileUpload ID="moreUpload3" runat="server" />
<asp:FileUpload ID="moreUpload4" runat="server" />
<asp:Button ID="uploadMoreFilesBtn" runat="server" Text="Upload" OnClick ="uploadMoreClicked" CausesValidation="false" />
<br />
<asp:Label ID="uploadInfoLbl" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Here's the code behind file event for button:
protected void uploadMoreClicked(object sender, EventArgs e)
{
int countFiles = 0;
if (moreUpload1.HasFile)
{
moreUpload1.PostedFile.SaveAs(Server.MapPath("/Upload/") + moreUpload1.FileName);
string fn2 = moreUpload1.FileName;
bool status2 = blReg.insertFiles(fn2, FileID);
countFiles++;
}
if (moreUpload2.HasFile)
{
moreUpload2.PostedFile.SaveAs(Server.MapPath("/Upload/") + moreUpload2.FileName);
string fn2 = moreUpload2.FileName;
bool status2 = blReg.insertFiles(fn2, FileID);
countFiles++;
}
if (moreUpload3.HasFile)
{
moreUpload3.PostedFile.SaveAs(Server.MapPath("/Upload/") + moreUpload3.FileName);
string fn2 = moreUpload3.FileName;
bool status2 = blReg.insertFiles(fn2, FileID);
countFiles++;
}
if (moreUpload4.HasFile)
{
moreUpload4.PostedFile.SaveAs(Server.MapPath("/Upload/") + moreUpload4.FileName);
string fn2 = moreUpload4.FileName;
bool status2 = blReg.insertFiles(fn2, FileID);
countFiles++;
}
uploadInfoLbl.Text = countFiles + " file(s) uploaded<br/>";
}
But button click event doesn't work. Please suggest me what i am doing wrong. Thanks in Advance!

ERROR :- DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Optiont4'

In .aspx page , I’ve taken Label Control in order to display question form the database,
4 radio buttons in order to display four option related to a particular question, and last but not the least, I’ve used hidden field in which I will store answer of the particular question.
And finally I’ve taken a Button Control, for which I’ve created the onclick event, on which I will perform the operation to generate score.
In .aspx.cs page, on the onclick event of the button, , I’ve fetch the controls form the aspx page using code mentioned below, and further I’ve used if statement in order to see which radio button is active and have store the corresponding value in the varialbe “selans”, using this “selans”, I will compare it with the value of hidden field in order to find whether checked radio button is the correct answer or not, it the answer is correct, i.e value in “selans” matches with the value in hidden field ( the actual answer) and the variable “count” ( initially initialized with value 0) increments accordingly, and all this code is placed in the “for loop” which will execute till the no. of controls in the GridView (you can relate it with the no. of question, as for every record GridView generates new control).
But when I run it I am getting this error :-
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Optiont4'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Optiont4'.
Source Error:
Line 115: <asp:RadioButton ID="rad2" runat="server" Text='<%#Eval("Option2") %>' GroupName="A" />
Line 116: <asp:RadioButton ID="rad3" runat="server" Text='<%#Eval("Option3") %>' GroupName="A" />
Line 117: <asp:RadioButton ID="rad4" runat="server" Text='<%#Eval("Optiont4")%>' GroupName="A" />
Line 118: <asp:HiddenField ID="hf" runat="server" Value='<%#Eval("CorrectAns")%>' />
Line 119:
Source File: e:\Way2Success\Student\Examdemo.aspx Line: 117
Here the error line number is 30 in .aspx page
Have a look at my code. Show me were I am making mistaking and what is the solution.
.aspx :-
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Examdemo.aspx.cs" Inherits="Student_Examdemo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form2" runat="server">
<div>
<div id="tabs">
<ul>
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
<li>Tab 4</li>
<li>Tab 5</li>
</ul>
<div id="tabs-1">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Question") %>'></asp:Label>
<br />
<br />
<br />
<asp:RadioButton ID="rad1" runat="server" Text='<%#Eval("Option1") %>' GroupName="A" />
<asp:RadioButton ID="rad2" runat="server" Text='<%#Eval("Option2") %>' GroupName="A" />
<asp:RadioButton ID="rad3" runat="server" Text='<%#Eval("Option3") %>' GroupName="A" />
<asp:RadioButton ID="rad4" runat="server" Text='<%#Eval("Option4") %>' GroupName="A" />
<asp:HiddenField ID="hf" runat="server" Value='<%#Eval("CorrectAns") %>' />
<br />
<br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div id="tabs-2">
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Question") %>'></asp:Label>
<br />
<br />
<br />
<asp:RadioButton ID="rad1" runat="server" Text='<%#Eval("Option1") %>' GroupName="A" />
<asp:RadioButton ID="rad2" runat="server" Text='<%#Eval("Option2") %>' GroupName="A" />
<asp:RadioButton ID="rad3" runat="server" Text='<%#Eval("Option3") %>' GroupName="A" />
<asp:RadioButton ID="rad4" runat="server" Text='<%#Eval("Optiont4")%>' GroupName="A" />
<asp:HiddenField ID="hf" runat="server" Value='<%#Eval("CorrectAns")%>' />
<br />
<br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div id="tabs-3">
Tab 3 Content
</div>
<div id="tabs-4">
Tab 4 Content
</div>
<div id="tabs-5">
Tab 5 Content
</div>
</div>
<input type="button" id="btnPrevious" value="Previous" style = "display:none"/>
<input type="button" id="btnNext" value="Next" />
<asp:Button class="panelButton" runat="server" Text="Finish the exam" ClientIDMode="Static" OnClick="btn_Click" />
<br />
</div>
</form>
</body>
</html>
.aspx.cs :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class Student_Examdemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = GetData("SELECT top 2 Question, Option1, Option2, Option3, Option4, CorrectAns, Explanation FROM Questions");
GridView1.DataBind();
GridView2.DataSource = GetData("SELECT top 2 Question, Option1, Option2, Option3, Option4, CorrectAns, Explanation FROM Questions WHERE SectionId=2");
GridView2.DataBind();
private DataSet GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
return ds;
}
}
}
}
protected void btn_Click(object sender, EventArgs e)
{
RadioButton r1, r2, r3, r4;
HiddenField hdn;
int count = 0;
int neg = 0;
int total;
int totalf=0;
int totals=0;
int totalt;
int totalfo;
int totalfi;
string selans = "-1";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
r1 = (RadioButton)GridView1.Rows[i].Cells[0].FindControl("rad1");
r2 = (RadioButton)GridView1.Rows[i].Cells[0].FindControl("rad2");
r3 = (RadioButton)GridView1.Rows[i].Cells[0].FindControl("rad3");
r4 = (RadioButton)GridView1.Rows[i].Cells[0].FindControl("rad4");
hdn = (HiddenField)GridView1.Rows[i].Cells[0].FindControl("hf");
if (r1.Checked)
{
selans = r1.Text;
}
else if (r2.Checked)
{
selans = r2.Text;
}
else if (r3.Checked)
{
selans = r3.Text;
}
else if (r4.Checked)
{
selans = r4.Text;
}
if (hdn.Value == selans)
{
count++;
}
else
{
neg--;
}
totalf = count + neg;
}
for (int i = 0; i < GridView2.Rows.Count; i++)
{
r1 = (RadioButton)GridView2.Rows[i].Cells[0].FindControl("rad1");
r2 = (RadioButton)GridView2.Rows[i].Cells[0].FindControl("rad2");
r3 = (RadioButton)GridView2.Rows[i].Cells[0].FindControl("rad3");
r4 = (RadioButton)GridView2.Rows[i].Cells[0].FindControl("rad4");
hdn = (HiddenField)GridView2.Rows[i].Cells[0].FindControl("hf");
if (r1.Checked)
{
selans = r1.Text;
}
else if (r2.Checked)
{
selans = r2.Text;
}
else if (r3.Checked)
{
selans = r3.Text;
}
else if (r4.Checked)
{
selans = r4.Text;
}
if (hdn.Value == selans)
{
count++;
}
else
{
neg--;
}
totals = count + neg;
}
total = totalf + totals;
Session["score"] = total;
}
}
You have a typing error in your GridView2 definition.
<asp:RadioButton ID="rad4" runat="server" Text='<%#Eval("Optiont4")%>' GroupName="A" />
should be
<asp:RadioButton ID="rad4" runat="server" Text='<%#Eval("Option4")%>' GroupName="A" />

Deleting images from server

I'm writing a code that selects images in a Listview and delete them from the server. Unfortunately I haven't been able to delete any image and no error during debug. Here is the code:
<asp:ListView ID="ListView2" runat="server" DataKeyNames="ID_BG" DataSourceID="SqlDataSource_BGdelete">
<ItemTemplate>
<label><input id="checkbox1" name="BG_list" type="checkbox" runat="server" value='<%# Eval("BG_fileName") %>'/>
<img alt="" style="width:150px" src="/Members/images/BG/icons/<%# Eval("BG_fileName") %>"></label>
</ItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" />
</div>
<div style="">
<asp:Button class="btn btn-default" ID="DeleteBackground" runat="server" Text="Delete" OnClick="DeleteBackground_click" />
</div>
</LayoutTemplate>
.....
CODE BEHIND
protected void DeleteBackground_click(object sender, EventArgs e)
{
foreach (ListViewItem itemRow in this.ListView2.Items)
{
var checkBtn = (HtmlInputCheckBox)itemRow.FindControl("checkbox1");
if (checkBtn.Checked)
{
string fileName = ("~/Members/images/BG/" + checkBtn.Value);
if (fileName != null || fileName != string.Empty)
{
if ((System.IO.File.Exists(fileName)))
{
System.IO.File.Delete(fileName);
}
}
}
}
}
These 2 lines
if ((System.IO.File.Exists(fileName)))
System.IO.File.Delete(fileName);
must be
if (System.IO.File.Exists(Server.MapPath(fileName)))
System.IO.File.Delete(Server.MapPath(fileName));
P.S.
It makes no sense to check if (fileName != null || fileName != string.Empty) because fileName is never null or empty.
certainly that the id="checkbox1" is rename by the renderer for not to have the same Id in item listView. Check the generated html.

Send information stored in a repeater to email recipient?

I would like to take all information stored in a repeater and place it in the body of an email message for sending. Basically, it's a product order form (which also makes use of a repeater) that sends users to an order review page with a form at the bottom that allows them to send the order information to someone else. I am allowed to set up the order information as a table. I have everything working, and my code successfully sends emails. However, I am not sure how to pull the order review repeater's contents into the message body for an email.
Any suggestions/tips are appreciated! Thanks!
Designer code:
<asp:Repeater ID="orderRepeater" runat="server" >
<itemtemplate>
<%# Eval("LocationName") %>
<div class="headerRow">
<div class="header">
<div class="thumb">
<p></p>
</div>
<div class="headerField name"><p class="hField">Product</p></div>
<div class="headerField sku"><p class="hField">GOJO SKU</p></div>
<div class="headerField size"><p class="hField">Size</p></div>
<div class="headerField case"><p class="hField">Case Pack</p></div>
<div class="headerField qty"><p class="hField">Quantity</p></div>
</div>
</div>
<div class="table">
<div class="row">
<div class="thumb"><%# Eval("Thumbnail") %></div>
<div class="field name"><p class="pField"> <%#Eval("ProductName") %> </p></div>
<div class="field sku"><p class="pField"> <%#Eval("Sku") %></p></div>
<div class="field size"><p class="pField"> <%#Eval("Size") %></p></div>
<div class="field case"><p class="pField"><%#Eval("CasePack") %></p></div>
<div class="field qty"><p class="pField"><%#Eval("Qty") %></p></div>
</div>
</div>
</itemtemplate>
</asp:Repeater>
<asp:placeholder id="form" runat="server">
<asp:label id="msgLbl" runat="server" text=""></asp:label>
<asp:hyperlink id="link" runat="server" visible="false" NavigateUrl="/united-states/market/office-buildings/obproductmap/ProductList" >Product Listing</asp:hyperlink><br />
<asp:hiddenfield id="emailTbl" runat="server"></asp:hiddenfield>
<div id="emailForm">
<asp:ValidationSummary ID="vsEmailForm" runat="server" ForeColor="red" DisplayMode="BulletList" /><br />
<div id="yourFields">
<div id="yNameInfo" class="fieldBlock">
<asp:requiredfieldvalidator runat="server" id="rfvYName" ForeColor="red"
ControlToValidate="yName" errormessage="You must enter your name" Text="*"
Display="Dynamic" SetFocusOnError="True"></asp:requiredfieldvalidator>
Your Name:<br /> <asp:TextBox runat="server" id="yName" size="40"></asp:TextBox>
</div>
<div id="yEmailInfo" class="fieldBlock">
<asp:requiredfieldvalidator runat="server" id="rfvYEmail" ForeColor="red"
ControlToValidate="yEmail" Display="Dynamic"
errormessage="You must enter your email" Text="*" SetFocusOnError="True"></asp:requiredfieldvalidator>
<asp:regularexpressionvalidator runat="server" id="revYEmail" ForeColor="red"
ControlToValidate="yEmail"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
errormessage="Your email address is not valid. Please try again." Text="*"
Display="Dynamic" SetFocusOnError="True"></asp:regularexpressionvalidator>
Your Email: <br /> <asp:TextBox runat="server" id="yEmail" size="40"></asp:TextBox><br /><br />
</div>
</div>
<div id="reFields">
<div id="rNameInfo" class="fieldBlock">
<asp:requiredfieldvalidator runat="server" id="rfvRName" ForeColor="red"
ControlToValidate="rName" Text="*"
errormessage="You must enter a recipient's name" Display="Dynamic"
SetFocusOnError="True"></asp:requiredfieldvalidator>
Recipient's Name: <br /><asp:TextBox runat="server" id="rName" size="40"></asp:TextBox>
</div>
<div id="rEmailInfo" class="fieldBlock">
<asp:requiredfieldvalidator runat="server" id="rfvREmail" ForeColor="red"
ControlToValidate="rEmail" Display="Dynamic" Text="*"
errormessage="You must enter a recipient's email" SetFocusOnError="True"></asp:requiredfieldvalidator>
<asp:regularexpressionvalidator runat="server" id="revREmail" ForeColor="red"
ControlToValidate="rEmail"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
errormessage="The recipient's email address is not valid. Please try again."
Text="*" Display="Dynamic" SetFocusOnError="True"></asp:regularexpressionvalidator>
Recipient's Email:<br /> <asp:TextBox runat="server" id="rEmail" size="40"></asp:TextBox><br /><br />
</div>
</div>
<div id="buttons">
<asp:Button id="submit" Text="Submit" runat="server" CausesValidation="true"
onclick="submitBtn" />
<asp:Button id="cancel" Text="Cancel" runat="server" CausesValidation="false" /><br /><br />
<asp:Button id="print" Text="Print" runat="server" CausesValidation="false "/>
<asp:Button id="pdf" Text="Save as PDF" runat="server" CausesValidation="false" />
</div>
</div>
</asp:placeholder>
<asp:placeholder id="sentMsg" visible="false" runat="server">
<asp:Label id="lbl" runat="server" Text="Your message has been sent!"></asp:Label>
</asp:placeholder>
Code behind:
protected void getOrder(Item CurrentItem)
{
Item HomeItem = ScHelper.FindAncestor(CurrentItem, "gojoMarket");
if (Session["orderComplete"] != null && Session["orderComplete"] != "")
{
if (HomeItem != null)
{
Item ProductGroup = HomeItem.Axes.SelectSingleItem(#"child::*[##templatename='gojoMarketOfficeBuildigProductMap']/*[##templatename='gojoOrderReview']");
Database db = Sitecore.Context.Database;
DataSet dset = new DataSet();
if (ProductGroup != null)
{
string InFromSession = Session["orderComplete"].ToString();
try
{
DataTable summary = dset.Tables.Add("summary");
summary.Columns.Add("LocationName", Type.GetType("System.String"));
summary.Columns.Add("Thumbnail", Type.GetType("System.String"));
summary.Columns.Add("ProductName", Type.GetType("System.String"));
summary.Columns.Add("Sku", Type.GetType("System.String"));
summary.Columns.Add("Size", Type.GetType("System.String"));
summary.Columns.Add("CasePack", Type.GetType("System.String"));
summary.Columns.Add("Qty", Type.GetType("System.String"));
summary.Columns.Add("Location", Type.GetType("System.String"));
Label qL = (Label)FindControl("qty");
string[] orders = InFromSession.Split(';');
string tempheader = "";
foreach (string order in orders)
{
DataRow drow = summary.NewRow();
if (order != "")
{
string[] things = order.Split(',');
string skus = things.GetValue(0).ToString();
if (skus != "")
{
Item locName = db.Items[skus];
Item LocationItem = ScHelper.FindAncestor(locName, "gojoProductLocation");
if (LocationItem != null)
{
string LocationName = LocationItem.Fields["Header"].ToString();
if (tempheader != LocationName)
{
drow["LocationName"] = "<div><h1>" + LocationName + "</h1></div>";
tempheader = LocationName;
}
}
}
}
string purchase = order;
int total = orders.GetUpperBound(0);
if (purchase != "")
{
string[] infos = purchase.Split(',');
string ids = infos.GetValue(0).ToString();
string qtys = infos.GetValue(1).ToString();
if (ids != "")
{
Item anItem = db.Items[ids];
Item orderItem = db.Items[anItem.Fields["Reference SKU"].Value];
if (orderItem != null)
{
Item marketItem = db.Items[orderItem.Fields["Master Product"].Value];
if (marketItem != null)
{
Item CPNItem = db.Items[marketItem.Fields["Complete Product Name"].Value];
drow["Thumbnail"] = "";
Sitecore.Data.Fields.XmlField fileField = marketItem.Fields["Thumbnail"];
drow["Thumbnail"] = "<image src=\"" + ScHelper.GetCorrectFilePath(fileField) + "\" border=\"0\" alt=\"\">";
if (CPNItem != null)
{
var name = CPNItem["Complete Name"];
drow["ProductName"] = name;
}
drow["Sku"] = marketItem.Fields["SKU"].Value;
drow["CasePack"] = marketItem.Fields["Case Pack"].Value;
if (marketItem.Fields["Size"] != null)
{
drow["Size"] = marketItem.Fields["Size"].Value;
}
else
{
drow["Size"] = "N/A";
}
drow["Qty"] = qtys.ToString();
summary.Rows.Add(drow);
}
}
}
}
}
orderRepeater.DataSource = dset;
orderRepeater.DataMember = "summary";
orderRepeater.DataBind();
}
catch (Exception x)
{
//
}
}
}
}
else
{
HyperLink none = (HyperLink)FindControl("link");
Label msg = (Label)FindControl("msgLbl");
none.Visible = true;
msg.Text = "You have not selected any items for purchase. To purchase items, please visit our complete product listing: ";
}
}
protected void sendEmail()
{
Item CurrentItem = Sitecore.Context.Item;
Item HomeItem = ScHelper.FindAncestor(CurrentItem, "gojoOrderReview");
if (HomeItem != null)
{
TextBox rTxt = (TextBox)FindControl("rEmail");
TextBox fName = (TextBox)FindControl("yName");
try
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(rTxt.Text);
msg.Subject = "GOJO product order summary";
msg.From = new System.Net.Mail.MailAddress("donotreply#GOJO.com");
msg.Body = "Here is a list of the products your friend, " + fName.Text + ", has selected: ";
msg.IsBodyHtml = true;
System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient("mail.innismaggiore.com");
sc.Send(msg);
}
catch (Exception EX)
{
GOJOHelper.WriteLog("GOJO Order Review - sendEmail()", EX.ToString());
}
}
}
protected void submitBtn(object sender, EventArgs e)
{
if (Page.IsValid)
{
Database db = Factory.GetDatabase("master");
PlaceHolder form = (PlaceHolder)FindControl("form");
PlaceHolder sent = (PlaceHolder)FindControl("sentMsg");
using (new SecurityDisabler())
{
sendEmail();
form.Visible = false;
sent.Visible = true;
}
}
}
}
I think this answer has what you're looking for. Basically, you can use javascript to send the html to the server in order to include it in your email:
asp.net get html controls in code behind
Also, make sure you include a ValidateRequest="false" on the page in order to post back html
if someone else has same problem and the repeater object has no image this solution is simple and easy instead of trust to a client javascript feedback !!
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =new HtmlTextWriter(stringWrite);
Repeater1.RenderControl(htmlWrite);string emailContent = stringWrite.ToString();

ASP AJAX TABS Sys.InvalidOperationException ERROR

Hello everyone I have a webform which uses ajax tabs inside the content teplte of the tab I put an user control here is an exapmple
<ajaxtoolkit:tabcontainer id="StyledTabContainer" runat="server" activetabindex="0"
width="600px" cssclass="MyTabStyle">
<!-- Overview Tab -->
<ajaxToolkit:TabPanel HeaderText="Overview" CssClass="none" runat="server" ID="TabPanel1" OnClientClick="PanelClickHide">
<ContentTemplate>
<div>
<h3>Overview</h3>
<p>
<over:Overview id="overview" runat="server" />
</p>
</div>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<!-- Pre-test Tab -->
<ajaxToolkit:TabPanel HeaderText="Pre-test" runat="server" ID="TabPanel2" OnClientClick="PanelClickHide">
<ContentTemplate>
<h3>Pre-test</h3>
<br />
<p>
<pre:PreTest id="pretest" runat="server" />
</p>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<!-- Webcast -->
<ajaxToolkit:TabPanel HeaderText="Webcast" runat="server" ID="TabPanel3" OnClientClick="PanelClick">
<ContentTemplate>
<h3>Webcast</h3>
<br />
<p id="pvisible" style="display:none">
<vid:Video id="vid1" runat="server"/>
</p>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<!-- Post-test Tab -->
<ajaxToolkit:TabPanel HeaderText="Post-test" runat="server" ID="TabPanel4" OnClientClick="PanelClickHide">
<ContentTemplate>
<h3>Post-Test</h3>
<br />
<p>
<post:Post id="post" runat="server" />
</p>
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxtoolkit:tabcontainer>
inside the user control I have a submit button.
on a webform where ajax tabs are located i control which tab to open or close here is example
if (status.Part1StartDate != null)
{
StyledTabContainer.ActiveTabIndex = 1;
TabPanel1.Enabled = false;
TabPanel2.Enabled = true;
TabPanel3.Enabled = false;
TabPanel4.Enabled = false;
TabPanel5.Enabled = false;
TabPanel6.Enabled = false;
}
if (status.Part1Done == true)
{
StyledTabContainer.ActiveTabIndex = 2;
TabPanel1.Enabled = false;
TabPanel2.Enabled = false;
TabPanel3.Enabled = true;
TabPanel4.Enabled = false;
TabPanel5.Enabled = false;
TabPanel6.Enabled = false;
}
whenever i Click a button inside the user control which is inside the content template I get this error.
Microsoft JScript runtime error: Sys.InvalidOperationException:
Handler was not added through the Sys.UI.DomEvent.addHandler method.
Any help please.....
Thank You

Categories