Deleting images from server - c#

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.

Related

File is getting saved when uploaded 2nd time

<div class="PriceCalculatorForm">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="PnlSaveData" runat="server">
<div class="form-group">
<div class="col-md-1"></div>
<label class="control-label col-sm-4">Upload Image</label>
<div class="col-sm-4">
<asp:FileUpload ID="ImageFileUploader" runat="server" />
<asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</div>
<div class="col-md-2">
<asp:Button ID="btnImageUpload" runat="server" Text="Upload Image" OnClick="btnImageUpload_Click" CssClass="btnSearch" />
</div>
<div class="col-md-1"></div>
</div>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnImageUpload" />
</Triggers>
</asp:UpdatePanel>
</div>
protected void btnImageUpload_Click(object sender, EventArgs e)
{
if (ImageFileUploader.HasFile)
{
string FileExtension = Path.GetExtension(ImageFileUploader.FileName);
if (FileExtension.ToLower() == ".jpg" || FileExtension.ToLower() == ".jpeg" || FileExtension.ToLower() == ".png" || FileExtension.ToLower() == ".gif")
{
string FileName = ImageFileUploader.FileName;
//Saving the file
ImageFileUploader.SaveAs(Server.MapPath("~/Images/" + FileName));
}
}
else
{
lblMsg.Text = "Please select file to upload";
lblMsg.ForeColor = System.Drawing.Color.Red;
}
}
Problem:
After running code when file is uploaded for first time it goes in else part of code, but the same file when uploaded again it work properly and file is saved at specified location. This is happening every time of execution. I am not getting what is going wrong.
Please any one can guide me on this?
change your form tag to this if you are mot using like this:
<form action="" method="post" enctype="multipart/form-data" id="form">
// your code
</form>
Everyone thank you for your support. Finally I got the solution and end up by adding this.Page.Form.Enctype = "multipart/form-data" under Page_Load Event.
protected void Page_Load(object sender, EventArgs e)
{
this.Page.Form.Enctype = "multipart/form-data";
}

Locate control in asp:listview when I have the clientid for the control?

VS2012, .NET 4.51, WebForms
From a click event in the code behind I have the client ID for a control within the ItemTemplate (naturally said control is created for each of the records within the listview):
var lastControlWithFocusClientId = "cphContainer_ucTakeTest_lvData_txtAnswer_0";
I need to find that control so I tried:
lvData.FindControl(lastControlWithFocusClientId)
and
Page.FindControl(lastControlWithFocusClientId)
However both return null (ie control not found.) So what am I missing here?
EDIT ListView markup added:
<asp:ListView runat="server"
ID="lvData"
ItemType="MyItemType"
SelectMethod="GetQuestions"
OnItemDataBound="lvData_OnItemDataBound" OnItemCreated="lvData_ItemCreated">
<ItemTemplate>
<tr>
<td><span class="label label-info"><%#: Item.QuestionNumber %></span></td>
<td>
<asp:Label ID="lblQuestionText" runat="server" Text='<%# Eval("QuestionText") %>' />
</td>
<td>
<img src='/ImageHandler.ashx?questionNo=<%#: Item.QuestionNumber %>'>
</td>
<td>
<div class="input-group">
<asp:TextBox data-sessionid='<%# SessionsId %>' data-question-no='<%#: Item.QuestionNumber %>' Enabled='<%# !ShowStudentResults %>' CssClass="form-control FlyoutCandidate" ID="txtAnswer" runat="server"></asp:TextBox>
<span data-content='<%#: GetAnswerInstructions(Item.SolutionType) %>' class="input-group-addon flyout-candidate-hint"><span class="glyphicon glyphicon-comment"></span></span>
<span class="input-group-addon special-character-toggle"><span class="glyphicon glyphicon-credit-card"></span></span>
</div>
</td>
<td>
<img runat="server" data-sessionid='<%# SessionsId %>' data-qno='<%# Item.QuestionId %>' data-id='<%# Item.QuestionNumber %>' onclick="javascript: TakeTestJs.DisplayQuestionHelp(this); return false;" src="/Images/help-icon.png" width="32" height="32" alt="" />
</td>
<td>
<asp:Panel runat="server" ID="imgHint"></asp:Panel>
</td>
<td>
<asp:Label CssClass="label label-info" ID="lblStudentMark" runat="server" Text='<%# Item.StudentMark %>' />
</td>
<td>
<asp:Label CssClass="label label-primary" ID="lblOutOf" runat="server" Text='<%# Item.QuestionOutOf %>' />
</td>
<td>
<asp:Label ID="lblSolutionText" runat="server" Text='<%# Item.SolutionText %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
findcontrol is not recursive, so you have to do a bit of workaround. Here is my code, modified version of what I got from somehwere around here:
private Control RecursiveFindControl(Control targetControl, string findControlId) {
if (targetControl.HasControls()) {
foreach (Control childControl in targetControl.Controls) {
if (childControl.ID == findControlId) {
return childControl;
}
RecursiveFindControl(childControl, findControlId);
}
}
return null;}
just use:
RecursiveFindControl(this, ControlName)
Since you are using .NET4 and higher, you can actually set the ClientMode property and set this yourself so you don't even have to work with the confusing ClientIDs that are generated by ASP.NET and nested server controls.
Check out this MSDN article for the ClientIDMode property
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode%28v=vs.110%29.aspx
Otherwise, to maybe more accurately answer your question, you can't do a FindControl on the controls collection itself because it will fail.
Typically when I work with a ListView, I end up taking the control that triggers the event for that row.
So if I have a LinkButton in the row, and I have a click event, I will do the following
protected void btnConfirm_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
ListViewDataItem row = btn.NamingContainer as ListViewDataItem;
if (row != null)
{
HiddenField hiddenFieldWithSomething = row.FindControl("hiddenControl") as HiddenField;
//var lastControlWithFocusClientId = cphContainer_ucTakeTest_lvData_txtAnswer_0";
if (hiddenFieldWithSomething.ClientID == lastControlWithFocusClientId)
{
//Do something here
}
}
}
When doing it this way, it's a little more fine-tuned and you still go through your typical event handler.
The RecursiveFindControl helper that was posted in this question will give you a much more robust and reusable solution.
I ended up implementing the following recursive search as #user2930100 did not work for me:
private Control RecursiveFindControl(Control aRootControl, string aFindControlClientId)
{
if (aRootControl.ClientID == aFindControlClientId)
return aRootControl;
foreach (Control ctl in aRootControl.Controls)
{
Control foundControl = RecursiveFindControl(ctl, aFindControlClientId);
if (foundControl != null)
return foundControl;
}
return null;
}

Passing variables to javascript in onclientclick

Okay, i think i've tried 3-4 methods here from stackoverflow, but none seems to work.
I've got:
OnClientClick='<%# Eval("albumName", "doConfirm(\"delete\", \"{0}\");").ToString() %>'
but in html it renders as:
onclick="doConfirm("delete", "Test");"
Also tried making a method to call:
public string CreateConfirmation(String action, String item) {
return String.Format(#"return confirm('Sikker på du vil {0}: {1}');", action, item);
}
With this:
OnClientClick='<%# CreateConfirmation("delete", (string)Eval(albumName)) %>'
But gives me exact same problem....
So im pretty lost?
I apologize in advance for such a long answer, but I wanted to be thorough.
This is apparently a "security" feature in .Net 4.0 (and higher). You can read more about it at:
http://avinashsing.sunkur.com/2010/10/29/asp-net-html-encoding-attributes-in-server-controls/
http://forums.asp.net/p/1554455/3818604.aspx
Stop the tag builder escaping single quotes ASP.NET MVC 2
All of the above links also recommend declaring a public class to override the behavior:
public class HtmlAttributeNoEncoding : System.Web.Util.HttpEncoder
{
protected override void HtmlAttributeEncode(string value, System.IO.TextWriter output)
{
output.Write(value);
}
}
and then adding this to the <system.web> element in your web.config:
<httpRuntime encoderType="HtmlAttributeNoEncoding"/>
This definitely fixes the rendering problem, so that quotes and apostrophes render as " and ' (as expected).
That said, I tested your problem with the following:
<script type="text/javascript">
var doConfirm = function (action, item) {
alert('Sikker på du vil ' + action + ': ' + item);
return false;
};
</script>
<p>Some "arbitrary" text. <asp:Button ID="Button3" runat="server" Text="Button" OnClientClick="doConfirm('delete', 'myalbum');" /></p>
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick='<%# Eval("albumName", "doConfirm(\"delete\", \"{0}\");").ToString() %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Album Name" DataField="albumName" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button2" runat="server" Text="Button" OnClientClick='<%# CreateConfirmation("delete", (string)Eval("albumName")) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and in the code-behind:
public partial class _Default : System.Web.UI.Page
{
public string CreateConfirmation(String action, String item)
{
return String.Format(#"return doConfirm('{0}', '{1}');", action, item);
}
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("albumName", typeof(string));
DataRow dr = null;
dt.Columns.Add(dc);
dr = dt.NewRow();
dr["albumName"] = "Zen Arcade";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["albumName"] = "New Day Rising";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["albumName"] = "Candy Apple Grey";
dt.Rows.Add(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
I was able to duplicate your rendering problem:
<p>Some "arbitrary" text.
<input type="submit" onclick="doConfirm('delete', 'myalbum');" value="Button" name="ctl00$MainContent$Button3" id="MainContent_Button3" />
</p>
<div>
<table cellspacing="0" rules="all" border="1" id="MainContent_GridView1"
style="border-collapse:collapse;">
<tr>
<th scope="col"> </th>
<th scope="col">Album Name</th>
<th scope="col"> </th>
<th scope="col">albumName</th>
</tr>
<tr>
<td>
<input type="submit" onclick="doConfirm("delete", "Zen Arcade");" value="Button" name="ctl00$MainContent$GridView1$ctl02$Button1" id="MainContent_GridView1_Button1_0" />
</td>
<td>Zen Arcade</td>
<td>
<input type="submit" onclick="return doConfirm('delete', 'Zen Arcade');" value="Button" name="ctl00$MainContent$GridView1$ctl02$Button2" id="MainContent_GridView1_Button2_0" />
</td>
<td>Zen Arcade</td>
</tr>
<tr>
<td>
<input type="submit" onclick="doConfirm("delete", "New Day Rising");" value="Button" name="ctl00$MainContent$GridView1$ctl03$Button1" id="MainContent_GridView1_Button1_1" />
</td>
<td>New Day Rising</td>
<td>
<input type="submit" onclick="return doConfirm('delete', 'New Day Rising');" value="Button" name="ctl00$MainContent$GridView1$ctl03$Button2" id="MainContent_GridView1_Button2_1" />
</td>
<td>New Day Rising</td>
</tr>
<tr>
<td>
<input type="submit" onclick="doConfirm("delete", "Candy Apple Grey");" value="Button" name="ctl00$MainContent$GridView1$ctl04$Button1" id="MainContent_GridView1_Button1_2" />
</td>
<td>Candy Apple Grey</td>
<td>
<input type="submit" onclick="return doConfirm('delete', 'Candy Apple Grey');" value="Button" name="ctl00$MainContent$GridView1$ctl04$Button2" id="MainContent_GridView1_Button2_2" />
</td>
<td>Candy Apple Grey</td>
</tr>
</table>
</div>
When any of the buttons were clicked, the JavaScript function ignored the HTML encoding, alerting me to:
Sikker på du vil delete: Zen Arcade
so while it looks funky in the source, having quotes and apostrophes render as " and ' doesn't really appear to affect anything.
Try the following:
<asp:Button OnClientClick="Delete(this);" Text='<%# Eval("albumName"); %>' />
JS:
function Delete(element) {
var value = element.value;
return confirm('Delete' + value + '?');
}
Just attach the event server side inside rowDataBound event like, (you can replace linkbutton with Button)
LinkButton myLinkButton=(LinkButton)e.row.FindControl("yourButtonName");
if(myLinkButton!=null)
{
myLinkButton.Attributes.Add("onclick","javascript:return confirm ('Are you sure you want to delete "+ DataBinder.Eval(e.row.DataItem, "YourDbField") + " ?');");
}
Even though this question is 5 years old, I wanted to follow up as I had the same issue with an ImageButton and was able to resolve it using a HiddenField.
Background: I have a Web User Control which I wanted to have a help button displayed if there was help available.
I added a HiddenField and an ImageButton to the User Control. I then created a property on the control so the developer may add help text.
ASPX Page
<asp:HiddenField ID="hidHelpText" runat="server" />
<asp:ImageButton ID="imgHelp" runat="server" ImageUrl="~/images/help.png" Visible="False" />
Code Behind (CS File)
public string HelpText
{
get { return hidHelpText.Value; }
set { hidHelpText.Value = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
imgHelp.Visible = !string.IsNullOrEmpty(HelpText);
imgHelp.OnClientClick = string.Format("MsgBox({0}.value, MessageButtons.OK); return false;", hidHelpText.ClientID);
}
This gets around the issue as the text belongs to the hidden field instead of trying to include it within the JavaScript for the OnClientClick property.
BTW: I cannot copy and paste so this code may contain some typos but I believe it is correct. At least it points the way so you may be able to work around the issue.

Target accordion pane content template after databind so that I can load data on demand?

I have an accordion that has another accordion inside one of its panes. This inner accordion is created using a datasource so each of its panes are loaded from a list of objects. In this particular case, this datasource is also loaded on demand. Now, where I'm stuck is that I want to be able to load the pane headers only and then load the contents when the pane is clicked; similar to what I have in the outer pane. The reason I'm confused here, is because the lazy load happens when the pane is clicked, but since this happens AFTER the databind, I don't know how to reference the content of the pane that invokes the ItemCommand. Not sure if that makes sense. Here is the inner accordion:
<ajaxToolkit:Accordion runat="server" ID="accReviewers" OnItemDataBound="accOuterAccordion_ItemDataBound" ContentCssClass="ReviewerContent" RequireOpenedPane="False" SelectedIndex="-1" OnItemCommand="accReviewers_ItemCommand">
<HeaderTemplate>
<div>
<asp:LinkButton Text='<%#Eval("Header") %>' CssClass="InReviewHeader" runat="server"
CommandName="LoadReviewers" CommandArgument='<%#Eval("MocRequestId") %>'/>
</div>
</HeaderTemplate>
<ContentTemplate>
<div>
<asp:ListView runat="server" ID="lvReviewers" ItemPlaceholderID="phReviewer" OnItemDataBound="lvReviewers_ItemDataBound">
<LayoutTemplate>
<div>
<asp:HyperLink runat="server" ID="lnkGotoRequest" Text="View this request"/>
</div>
<asp:PlaceHolder runat="server" ID="phReviewer"/>
<div style="margin-top: 5px;">
<asp:Button runat="server" ID="btnResubmit" Text="Resubmit" CssClass="ResubmitInitial"/>
</div>
</LayoutTemplate>
<ItemTemplate>
<div class="ReviewerItem">
<%#Eval("Assignee.Name") %><br />
<img src="" alt="Reviewer" runat="server" ID="imgReviewer" width="75" style="border: 1px solid gray; border-radius: 6px;"/><br />
<asp:Label runat="server" ID="lblStatus" Text='<%#Eval("ReviewStatus") %>' />
<asp:HyperLink runat="server" ID="lnkRejectComment" CssClass="InitialRejectComment">(details)</asp:HyperLink>
</div>
</ItemTemplate>
</asp:ListView>
</div>
</ContentTemplate>
</ajaxToolkit:Accordion>
</Content>
</ajaxToolkit:AccordionPane>
As you can see, the accordion accReviewers is generated via a DataSource. The listview contained in the LayoutTemplate will not have its datasource bound until the LinkButton has been clicked, which will fire the item command. Also worth noting that this entire accordion is wrapped in an UpdatePanel.
This is the code behind I was starting to work with, but it doesn't appear to get the correct instance of the listview and while the list is not empty, it will not display anything:
protected void accReviewers_ItemCommand(object sender, CommandEventArgs e)
{
var mocId = int.Parse(e.CommandArgument.ToString());
var list = (sender as AjaxControlToolkit.Accordion).FindControl("lvReviewers") as ListView; //APPARENTLY WRONG
var reviewers = MocApi.GetReviews(mocId);
list.DataSource = reviewers;
list.DataBind();
}
So to recap, when the LinkButton within the HeaderTemplate is clicked, I need to somehow gain reference to the correct instance of the ListView so that I can bind its datasource. As always, any help or insight is appreciated. This is similar to a previous question of mine but is specific to gaining this reference after databind which seems a bit more complicated. TIA
UPDATE:
I found that I can bind the item datasource if I can somehow capture its index. I'm exploring trying to set that as a command argument during the databinding of the inner accordion.
I managed to solve this with some minor shenannigans:
Here is the markup:
<ItemTemplate>
<div class="ReviewerItem">
<%#Eval("Assignee.Name") %><br />
<div style="display: inline-block; position: relative;">
<img src="" alt="Reviewer" runat="server" ID="imgReviewer" width="75" style="border: 1px solid lightgray; border-radius: 6px; overflow: hidden;"/><br />
<div runat="server" ID="divYes" Visible="False">
<img src="../Images/Yes.png" alt="Approved" class="ApprovalIcon" />
</div>
<div runat="server" ID="divNo" Visible="False">
<img src="../Images/No.png" alt="Rejected" class="ApprovalIcon" id="imgNo" />
</div>
</div>
<asp:Label runat="server" ID="lblStatus" Text='<%#Eval("ReviewStatus") %>' />
<asp:HyperLink runat="server" ID="lnkRejectComment" CssClass="InitialRejectComment">(details)</asp:HyperLink>
<asp:Panel runat="server" ID="pnlDemoApproval" Visible="False" CssClass="DemoButtons">
<asp:Button runat="server" ID="btnApprove" Text="Approve" CommandArgument='<%#Eval("Assignee.Guid") + "|" + Eval("Ticketid") %>' CommandName="ApproveReview"/>
<asp:Button runat="server" ID="btnDeny" Text="Deny" CommandArgument='<%#Eval("Assignee.Guid") + "|" + Eval("Ticketid") %>' CommandName="DenyReview"/>
</asp:Panel>
<ajaxToolkit:BalloonPopupExtender runat="server" ID="balloon" BalloonPopupControlID="pnlPopup"
TargetControlID="lnkRejectComment" Position="TopRight" BalloonStyle="Cloud" BalloonSize="Medium" DisplayOnMouseOver="True"/>
<asp:Panel runat="server" ID="pnlPopup">Rejection Reason</asp:Panel>
</div>
</ItemTemplate>
On databind, I catch the item so that I can grab the index and set it to the CommandName for later use:
AjaxControlToolkit.AccordionItemEventArgs e)
{
if (e.ItemType != AjaxControlToolkit.AccordionItemType.Content) return;
var index = e.ItemIndex;
var button = e.AccordionItem.Parent.FindControl("lnkbHeader") as LinkButton;
if (button != null) button.CommandName = index.ToString();
}
Now that control contains the index, i can use that to target the correct pane and bind its datasource:
protected void accReviewers_ItemCommand(object sender, CommandEventArgs e)
{
//This seems stupid to put here, but for some reason the item command bypasses the listview catch and passes it to the accordion
if (e.CommandName == "ApproveReview")
{
var assigneeGuid = new Guid(e.CommandArgument.ToString().Split('|')[0]);
var ticketId = int.Parse(e.CommandArgument.ToString().Split('|')[1]);
var ticket = new MocApproval(ticketId);
DoDemoApproval(ticketId, assigneeGuid, true);
var approvalIndex = (sender as AjaxControlToolkit.Accordion).SelectedIndex;
var lv =
(sender as AjaxControlToolkit.Accordion).Panes[approvalIndex].FindControl("lvReviewers") as ListView;
lv.DataSource = MocApi.GetReviews(ticket.MocRequest);
lv.DataBind();
return;
}
if (e.CommandName == "DenyReview")
{
var assigneeGuid = new Guid(e.CommandArgument.ToString().Split('|')[0]);
var ticketId = int.Parse(e.CommandArgument.ToString().Split('|')[1]);
var ticket = new MocApproval(ticketId);
DoDemoApproval(ticketId, assigneeGuid, false);
var approvalIndex = (sender as AjaxControlToolkit.Accordion).SelectedIndex;
var lv =
(sender as AjaxControlToolkit.Accordion).Panes[approvalIndex].FindControl("lvReviewers") as ListView;
lv.DataSource = MocApi.GetReviews(ticket.MocRequest);
lv.DataBind();
return;
}
...

Default page code behind not working when published on hosting server

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"

Categories