Not getting posted file in asp.net 3.5. FileUpload control - file-upload

this my code in my user control's designer file
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ucImageList.ascx.cs"
Inherits="Pariwaar.UserControl.ucImageList" %>
<asp:ScriptManagerProxy ID="ajaxScriptManagerProxy" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:HiddenField ID="hidUserId" runat="server" />
<asp:HiddenField ID="hidAlbumId" runat="server" />
<table>
<tr>
<td>
<asp:FileUpload ID="fvUploadFile" runat="server" EnableViewState="true" />
<asp:LinkButton ID="AddImageInfoButton" CssClass="blueLink" runat="server" Text="Upload"
OnClick="AddImageInfoButton_Click"></asp:LinkButton>
</td>
</tr>
<tr>
<td>
<asp:DataList ID="DtLstImageList" runat="server" DataSourceID="odsImageList" OnItemCommand="DtLstImageList_ItemCommand"
EnableTheming="true" RepeatColumns="4" RepeatDirection="Horizontal">
<ItemTemplate>
<ul>
<li style="display: block; text-align: center;">
<asp:ImageButton ID="ImgBtnImagePath" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImagePath")%>'
ImageAlign="Middle" Width="100" Height="100" CommandName="ViewImage" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ImageId")%>' />
</li>
<li style="display: block;">
<asp:Button ID="UpdateCoverPageImage" runat="server" Text="Set as Cover Page" CssClass="inputButtonWithoutpadding"
CommandName="SetAsCoverPage" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ImageId")%>' />
</li>
</ul>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:ObjectDataSource ID="odsImageList" runat="server" SelectMethod="GetImageInfo"
TypeName="Pariwaar.Controller.GallaryHandler" DeleteMethod="DeleteImageInfo">
<DeleteParameters>
<asp:Parameter Name="ImageId" Type="Int64" />
</DeleteParameters>
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="ImageId" Type="Int64" />
<asp:ControlParameter ControlID="hidAlbumId" Name="AlbumId" PropertyName="Value"
Type="Int64" DefaultValue="0" />
</SelectParameters>
</asp:ObjectDataSource>
i am not getting Fiepath/name and Fileupload controls' posted file property is null
i am checking fvFileUpload.Postedfile in click event of AddImageInfoButton
can anybody please tell me what i am doing wrong in this code...
-thanks in advance

File uploads are not supported in async postbacks, such as when you use the UpdatePanel. Read this blog post for more details.
Here are two proposed workarounds:
Have a dedicated "Upload" button that does a regular postback instead of an async postback. You can achieve this using several techniques: Have the button be outside all UpdatePanels; have the button be the target of an UpdatePanel's PostBackTrigger; or call ScriptManager.RegisterPostBackControl() on it.
Have a dedicated file upload page that doesn't have any UpdatePanels. Many web sites already do this anyway.

Related

how do you preselect checkboxlist items in edititemtemplate in vb.net

I have a checkboxlist in a formview itemtemplate. In edit mode I want to select the items that are in a datatable. I cannot find how to do this. I am using VB.NET.
ASP.NET code:
<asp:FormView ID="rdf" runat="server" Width="100%" DataSourceID="sqldatasource1" OnItemCreated="rdf_ModeChanging" rendermode="Lightweight" onrowupdating="updatebutton_click" DataKeyNames="applicationid" >
<ItemTemplate>
<fieldset style="width: 97%">
<div>
<br />
<asp:Label runat="server" ID="FiscalOrgNameLabel2" Text="Fiscal Organization: " Style="font-weight: bold; font-size: 15px;"></asp:Label><asp:Label Text='<%# Eval("FiscalOrgName") %>' runat="server" ID="FiscalOrgNameLabel1" />
</div>
<br />
<asp:panel id="cntyPanel" runat="server" >
<asp:label ID="countyLabel" runat="server" style="font-weight: bold; font-size: 15px; "
text="County(s): (if applicable)">
<asp:DataList ID="dlCounty" runat="server" DataSourceID="sqlCounty" Style="font-weight: normal;" >
<ItemTemplate>
<li>
<%# Eval("county") %>
</li>
</ItemTemplate>
</asp:DataList>
</asp:label>
</asp:panel>
<asp:panel id="IHEPanel" runat="server" >
<asp:label ID="instLabel" runat="server" style="font-weight:bold; font-size: 15px; "
text="Institution(s): (if applicable)">
<asp:datalist ID="dlIHE" runat="server" DataSourceID="sqlIHE" style="font-weight:normal;">
<ItemTemplate>
<li >
<%# Eval("Institute") %>
</li>
</ItemTemplate>
</asp:datalist>
</asp:label>
</asp:panel>
<asp:SqlDataSource ID="sqlCounty" runat="server" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' SelectCommand="SELECT dbo.County.County as county, dbo.Application_County.ApplicationId, dbo.Application_County.CountyId
FROM dbo.County INNER JOIN
dbo.Application_County ON dbo.County.CountyID = dbo.Application_County.CountyId where applicationid=#appid">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="appid" Name="appid"></asp:QueryStringParameter>
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource runat="server" ID="sqlGetBehalf" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' SelectCommand="getBehalf" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="appid" Name="appid" Type="Int32"></asp:QueryStringParameter>
<asp:QueryStringParameter QueryStringField="apptypeid" Name="apptypeid" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource runat="server" ID="sqlIHE" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' selectcommand="SELECT dbo.Application_IHE.ApplicationID, dbo.IHE.Institute
FROM dbo.Application_IHE INNER JOIN
dbo.IHE ON dbo.Application_IHE.IHE = dbo.IHE.iheID where applicationid = #appid" SelectCommandType="text">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="appid" Name="appid" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
</asp:SqlDataSource>
<div>
<div class="rdfCommandButtons">
<hr class="rdfHr" />
<telerik:RadButton runat="server" ButtonType="SkinnedButton" RenderMode="Lightweight" CommandName="Edit" Text="Edit" ID="EditButton" ToolTip="Edit" CausesValidation="False" />
</div>
</fieldset>
</ItemTemplate>
<EditItemTemplate>
<fieldset style="width: 97%"> <br />
<asp:Label ID="editApptypeId" runat="server" Text='<%# Eval("applicationtype") %>'></asp:Label>
<div style="display:table; width:100%">
<div style="display:table-row;">
<div style="display:table-cell;">
Fiscal Organizaton:
</div>
<div class="cell textcell">
<asp:TextBox ID="fiscalOrg" runat="server" Text='<%# Bind("FiscalOrgName") %>'></asp:TextBox>
</div>
</div>
</div>
<div id="cntyPanel" visible="true" runat="server">
<div runat="server" style="font-weight: bold; font-size: 15px;">
County(s):
<asp:CheckBoxList ID="ckCounty" runat="server" RepeatColumns="8" DataTextField="county" DataValueField="countyid" ></asp:CheckBoxList>
<br />
</div>
<div id="IHEPanel" visible="false" runat="server">
<div runat="server" style="font-weight:bold; font-size: 15px;">
Institution(s):
<asp:datalist ID="dlIHE" runat="server" DataSourceID="sqlIHE" style="font-weight:normal;">
<ItemTemplate>
<li >
<%# Eval("Institute") %>
</li>
</ItemTemplate>
</asp:datalist>
</div>
</div>
<asp:SqlDataSource runat="server" ID="sqlGetBehalf" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' SelectCommand="getBehalf" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="appid" Name="appid" Type="Int32"></asp:QueryStringParameter>
<asp:QueryStringParameter QueryStringField="apptypeid" Name="apptypeid" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
</asp:SqlDataSource>
</div>
<asp:SqlDataSource runat="server" ID="sqlIHE" ConnectionString='<%$ ConnectionStrings:COSIGrantsDB %>' selectcommand="SELECT dbo.Application_IHE.ApplicationID, dbo.IHE.Institute
FROM dbo.Application_IHE INNER JOIN
dbo.IHE ON dbo.Application_IHE.IHE = dbo.IHE.iheID where applicationid = #appid" SelectCommandType="text">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="appid" Name="appid" Type="Int32"></asp:QueryStringParameter>
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<EmptyDataTemplate>
<div>
<div class="rdfEmpty">There are no items to be displayed.</div>
</div>
</EmptyDataTemplate>
</asp:FormView>
VB.NET:
Protected Sub rdf_itemcommand(sender As Object, e As FormViewCommandEventArgs) Handles rdf.ItemCommand
Dim county As CheckBoxList = DirectCast(rdf.FindControl("ckCounty"), CheckBoxList)
conn.Open()
Using cmd As New SqlCommand("select * from application_County where applicationid =" + Request.QueryString("appid"), conn)
Using rdr = cmd.ExecuteReader()
If rdr.HasRows Then
Do While rdr.Read
For Each item As ListItem In county.Items
If item.Value = rdr.GetValue(2) Then
item.Selected = True
End If
Next
Loop
End If
End Using
End Using
End Sub
I get an error on county:
Object reference not set to an instance of an object.
When I debug it, county checkboxlist is empty. Why can't I find the checkboxlist in the edititemtemplate?
Without seeing the code you currently have it is a little difficult to guide you, however if you post the code I would be more than happy to help.
You are going to need a for loop in the code behind the goes through and sets everything to checked.
For each checkBoxItem as listItem in [NameOfCheckBox].Items
checkBoxItem.selected = true
next

LayoutTemplate does not contain an IEditableTextControl with ID UserName for the username

im making a website and ive never used visual studio 2012 before and having difficulty fixing the errors that are appearing, does anyone know what this error is about?
https://imagizer.imageshack.us/v2/821x409q90/661/407a87.png
<asp:Login runat="server" ViewStateMode="Disabled" RenderOuterTable="false">
<LayoutTemplate>
<p class="validation-summary-errors">
<asp:Literal runat="server" ID="FailureText" />
</p>
<fieldset>
<legend>Log in Form</legend>
<ol>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">Username</asp:Label>
<asp:TextBox runat="server" ID="UserName" Width="266px" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="Please enter your username." />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="Password">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" Width="263px" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password" CssClass="field-validation-error" ErrorMessage="Please enter your password." />
</li>
<li>
<asp:CheckBox runat="server" ID="RememberMe" />
<asp:Label runat="server" AssociatedControlID="RememberMe" CssClass="checkbox">Remember me?</asp:Label>
</li>
</ol>
<asp:Button runat="server" CommandName="Login" Text="Log in" />
</fieldset>
</LayoutTemplate>
</asp:Login>

Grid view won't show

I'm creating a website with two pages using a master page. I want to display all the content of my table in gridview on the second page upon logging in.
I don't know what went wrong and why my gridview on the second page won't display. But if I do it on the first page, it's working fine.
Imports System.Data
Imports System.Xml
Partial Class Default2
Inherits System.Web.UI.Page
Dim conn2 As New OleDb.OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;Data Source=" & Server.MapPath("~/App_Data/Tony.mdb"))
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("uname") = "" Then
iduser.Text = "Sorry you are not logged-in to view this page."
ElseIf Session("uname") = "Wrong username and/or password. Please try again." Or Session("uname") = "Successfully signed-up! Go back to the home page to log-in" Then
iduser.Text = Session("uname")
Else
Dim cload As New OleDb.OleDbDataAdapter("select * from sample where username='" & Session("uname") & "'", conn2)
Dim tester As New DataSet
iduser.Text = "Welcome " & Session("uname") & "!"
tester.Clear()
cload.Fill(tester)
Session("valid") = tester.Tables(0).DefaultView.Item(0).Item(9)
If Session("valid") = "y" Then
results.DataSource = tester.Tables(0).DefaultView
results.DataBind()
lfn.Visible = True
lln.Visible = True
lag.Visible = True
End If
End If
End Sub
Next is the aspx only now I have added a work around though I still want a clear explaination why wont the gridview show. As you can see I added a data source to the object as a result I didnt need to code the datasource or to databind anymore. Still, I prefer everything to be hard-coded.
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p style="height: 39px">
<asp:Label ID="iduser" runat="server"></asp:Label>
<asp:GridView ID="results" runat="server" AutoGenerateColumns="False"
Width="249px" EmptyDataText="No Records" DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField DataField="fname" HeaderText="fname" SortExpression="fname" />
<asp:BoundField DataField="lname" HeaderText="lname" SortExpression="lname" />
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
<asp:BoundField DataField="gender" HeaderText="gender"
SortExpression="gender" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/Tony.mdb"
SelectCommand="SELECT [fname], [lname], [age], [gender] FROM [sample] WHERE ([username] = ?)">
<SelectParameters>
<asp:SessionParameter Name="username" SessionField="uname" Type="String" />
</SelectParameters>
</asp:AccessDataSource>
<asp:Button ID="bsearch" runat="server" Text="Search:" Visible="False" />
<asp:TextBox ID="search" runat="server" Visible="False"></asp:TextBox>
</p>
<br />
<asp:ListBox ID="listsearch" runat="server" Width="216px"></asp:ListBox>
<br /><h2>
<asp:Label ID="Label1" runat="server" Text="Edit Profile Here:" Visible="False"></asp:Label>
</h2>
<p>
<asp:Label ID="lfn" runat="server" Text="First Name: "
Visible="False"></asp:Label>
<asp:TextBox ID="fname" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:Label ID="fn" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lln" runat="server" Text="Last Name: "
Visible="False"></asp:Label>
<asp:TextBox ID="lname" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:Label ID="ln" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lag" runat="server" Text="Age:" Visible="False"></asp:Label>
<asp:TextBox ID="age" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:Label ID="ag" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lgen" runat="server" Text="Gender: " Visible="False"></asp:Label>
<asp:DropDownList ID="gender" runat="server" Enabled="False" Visible="False">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
</p>
<p>
<asp:Label ID="lem" runat="server" Text="Email:" Visible="False"></asp:Label>
<asp:TextBox ID="email" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:Label ID="em" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lun" runat="server" Text="Username:" Visible="False"></asp:Label>
<asp:TextBox ID="username" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:Label ID="un" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lpw" runat="server" Text="Password:" Visible="False"></asp:Label>
<asp:TextBox ID="pass" runat="server" TextMode="Password" Enabled="False"
Visible="False"></asp:TextBox>
<asp:Label ID="pw" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="lpw2" runat="server" Text="Re-type Pass:" Visible="False"></asp:Label>
<asp:TextBox ID="pass2" runat="server" TextMode="Password" Enabled="False"
Visible="False"></asp:TextBox>
<asp:Label ID="pw2" runat="server" ForeColor="#CC3300"></asp:Label>
</p>
<p>
<asp:Label ID="ladm" runat="server" Text="Admin?" Visible="False"></asp:Label>
<asp:DropDownList ID="admin" runat="server" Visible="False">
<asp:ListItem>n</asp:ListItem>
<asp:ListItem>y</asp:ListItem>
</asp:DropDownList>
</p>
<p>
<asp:Button ID="bedit" runat="server" Text="Edit" Visible="False" />
<asp:Button ID="badd" runat="server" Text="Add Record" Visible="False" />
<asp:Button ID="bdelete" runat="server" Text="Delete Record" Visible="False" />
</p>
</asp:Content>
You might have forgot to open the connection? Can you edit this
conn2.Open
Before this line:
Dim cload As New OleDb.OleDbDataAdapter("select * from sample where username='" & Session("uname") & "'", conn2)

VB.net Single row list view across multiple lines

Is it possible to line break a listview control set to single row in visual studio similar to a wordwrap? So the line break occurs when a certain width is exceeded by the text, not where a certain number of results is exceeded (eg displaying the results as columns)
ie:
Matthew Chrinstina Fankie Daniel Angela James Simon Laura
as
Matthew Chrinstina Fankie
Daniel Angela James Simon
Laura
not
Matthew Chrinstina Fankie
Daniel Angela James
Simon Laura
Here is my asp which displays as a single row with alternating values embolden:
<div class="ExcludedStudent">
<asp:Label ID="lvlExcludedStudents" runat="server" CssClass="boldlabel" Text="Students excluded from the Progress Measure:"></asp:Label>
<asp:ListView ID="lvExcludedStudents" runat="server" DataSourceID="dsExcludedStudents">
<AlternatingItemTemplate>
<td runat="server" style="">
<asp:Label ID="Column1Label" runat="server" Text='<%# Eval("Column1") %>' Font-Bold="True" />
<br />
</td>
</AlternatingItemTemplate>
<EmptyDataTemplate>
<table style="">
<tr>
<td>None.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<td runat="server" style="">
<asp:Label ID="Column1Label" runat="server" Text='<%# Eval("Column1") %>' />
<br />
</td>
</ItemTemplate>
<LayoutTemplate>
<table runat="server" border="0" style="">
<tr runat="server" id="itemPlaceholderContainer">
<td runat="server" id="itemPlaceholder">
</td>
</tr>
</table>
<div style="">
</div>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="dsExcludedStudents" runat="server" ConnectionString="<%$ ConnectionStrings:MaltingsConnectionString %>" SelectCommand="spExcludedStudents" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="DdlYear" Name="StuYear" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlDataCollection" Name="DataCollection" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DdlSubject" Name="SubjectName" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DdlTeachingGroup" Name="TeachingGroup" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlSubgroup" Name="Subgroup" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
I found exactly what I was looking for here:
How to display UL elements as a flat comma-separated list
First set the listview to a bulleted list and then add the below to the CSS.
/*css to comma separate the unordered list*/
ul li{
display:block;
float:left;
_display:inline;
_float:none;
}
ul li::before{
content:",";
white-space:pre;
}
ul li:first-child::before{
content:"";
}
ul li:last-child::before{
content:" and";
white-space:pre;
}
ul + *{
clear:left;
}

FileUpload control inside update panel in SharePoint

I am developing an application in which is in SharePoint 2010.
I have used file upload control inside update panel, there is also two more text boxes for name and address. When i click on button i am not getting file name from file upload control.
Following is my code, please tell me where i am going wrong or whats the reason for not getting file control value after button click.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<table width="50%" cellpadding="2" cellspacing="0">
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" /><br />
<asp:Image ID="NormalImage" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Upload" />
</Triggers>
</asp:UpdatePanel>
can you remove the triggers section and try.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<table width="50%" cellpadding="2" cellspacing="0">
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" /><br />
<asp:Image ID="NormalImage" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Remove <asp:ScriptManager ID="ScriptManager1" runat="server" />
Add ScriptManager to Page programmatically:
protected override void OnInit(EventArgs e)
{
Page.Init += delegate(object sender, EventArgs e_Init)
{`enter code here`
if (ScriptManager.GetCurrent(Page) == null)
{
ScriptManager sMgr = new ScriptManager();
Page.Form.Controls.AddAt(0, sMgr);
}
};
base.OnInit(e);
}