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
When I edit items in a Listview from a Dropdown list and press the standard update button the data is not updating.
This is the structure of my database.
CREATE TABLE [dbo].[Assets]
(
[AssetID] [INT] IDENTITY(20000,1) PRIMARY KEY NOT NULL,
[Asset] NVARCHAR(20) NOT NULL,
[Symbol] NVARCHAR(20) NULL,
[AssetType] NVARCHAR(20) CONSTRAINT chk_asttype CHECK (assettype IN ('Currencies',
'Indices',
'Stocks',
'Commodities')) NOT NULL,CREATE TABLE[dbo].[times]
(
timeid [INT] IDENTITY(20010,1) PRIMARY KEY NOT NULL,
timevalues NVARCHAR (15) DEFAULT '15 Minutes' NOT NULL
)CREATE TABLE [dbo].[results]
(
[resultid] [INT] IDENTITY(20016,1) PRIMARY KEY NOT NULL,
[result] [NVARCHAR](10)CONSTRAINT chk_result CHECK (result IN ('Won',
'Lost',
'Draw',
'Prepare',
'New Signal'))
)CREATE TABLE [dbo].[binarysignals]
(
[signalid] [INT] IDENTITY(30000,1) PRIMARY KEY NOT NULL,
[assetid] [INT]CONSTRAINT fk_binastid FOREIGN KEY REFERENCES assets(assetid) NOT NULL,
[signaldate][DATE] DEFAULT Getdate() NOT NULL,
[direction][VARCHAR](4) CONSTRAINT chk_bindirection CHECK (direction IN ('Call',
'Put')) DEFAULT NULL,
[strikeprice] [SMALLMONEY] DEFAULT NULL,
[expiryprice] [SMALLMONEY] DEFAULT NULL,
[starttime][SMALLDATETIME] DEFAULT NULL,
[expirytime][NVARCHAR](20) DEFAULT NULL,
[resultid] [INT]CONSTRAINT fk_binresid FOREIGN KEY REFERENCES results(resultid) DEFAULT 20016 NOT NULL,
[lastupdatedtime][SMALLDATETIME] DEFAULT Getdate() NOT NULL,
)
And here is my ASP.Net markup code
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<script src="Scripts/jquery-1.9.1.min.js"></script>
$(document).ready(function () {
ShowTime();
});
function ShowTime() {
var dt = new Date();
document.getElementById("lblTime").innerHTML = dt.toLocaleTimeString();
window.setTimeout("ShowTime()", 1000);
}
<div>
<label id="lblTime" style="font-weight: bold"></label>
<br />
<asp:SqlDataSource ID="BO" runat="server" ConnectionString="<%$ ConnectionStrings:Signals2UConnectionString %>"
DeleteCommand="DELETE FROM [BinarySignals] WHERE [SignalID] = #SignalID" InsertCommand="INSERT INTO [BinarySignals] ([AssetID]) VALUES (#AssetID)" SelectCommand="SELECT [SignalID], BinarySignals.AssetID ,[Asset], [SignalDate], [Direction], [StrikePrice], [ExpiryPrice], [StartTime], [ExpiryTime], [Result],Results.ResultID FROM [BinarySignals]
INNER JOIN Assets On BinarySignals.AssetID=Assets.AssetID
INNER JOIN Results On BinarySignals.ResultID=Results.ResultID
ORDER BY BinarySignals.AssetID DESC"
UpdateCommand="UPDATE [BinarySignals] SET [AssetID] = #AssetID, [SignalDate] = #SignalDate, [Direction] = #Direction, [StrikePrice] = #StrikePrice, [ExpiryPrice] = #ExpiryPrice, [StartTime] = #StartTime, [ExpiryTime] = #ExpiryTime, [ResultID] = #ResultID WHERE [SignalID] = #SignalID">
<DeleteParameters>
<asp:Parameter Name="SignalID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="AssetID" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="AssetID" Type="Int32" />
<asp:Parameter DbType="Date" Name="SignalDate" />
<asp:Parameter Name="Direction" Type="String" />
<asp:Parameter Name="StrikePrice" Type="Decimal" />
<asp:Parameter Name="ExpiryPrice" Type="Decimal" />
<asp:Parameter Name="StartTime" Type="DateTime" />
<asp:Parameter Name="ExpiryTime" Type="String" />
<asp:Parameter Name="ResultID" Type="Int32" />
<asp:Parameter Name="SignalID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="Results" runat="server" ConnectionString="<%$ ConnectionStrings:Signals2UConnectionString %>" SelectCommand="SELECT [Result], [ResultID] FROM [Results]"></asp:SqlDataSource>
<asp:ListView ID="ListView1" runat="server" DataSourceID="BO" GroupItemCount="3" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<td id="Td1" runat="server" style="">SignalID:
<asp:Label ID="SignalIDLabel" runat="server" Text='<%# Eval("SignalID") %>' />
<br />
Asset:
<asp:Label ID="AssetLabel" runat="server" Text='<%# Eval("Asset") %>' />
<br />
SignalDate:
<asp:Label ID="SignalDateLabel" runat="server" Text='<%# Eval("SignalDate","{0:yyyy-MM-dd}") %>' />
<br />
Direction:
<asp:Label ID="DirectionLabel" runat="server" Text='<%# Eval("Direction") %>' />
<br />
StrikePrice:
<asp:Label ID="StrikePriceLabel" runat="server" Text='<%# Eval("StrikePrice") %>' />
<br />
ExpiryPrice:
<asp:Label ID="ExpiryPriceLabel" runat="server" Text='<%# Eval("ExpiryPrice") %>' />
<br />
StartTime:
<asp:Label ID="StartTimeLabel" runat="server" Text='<%# Eval("StartTime") %>' />
<br />
ExpiryTime:
<asp:Label ID="ExpiryTimeLabel" runat="server" Text='<%# Eval("ExpiryTime") %>' />
<br />
Result:
<asp:Label ID="ResultLabel" runat="server" Text='<%# Eval("Result") %>' />
<br />
ResultID:
<asp:Label ID="ResultIDLabel" runat="server" Text='<%# Eval("ResultID") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</AlternatingItemTemplate>
<EditItemTemplate>
<td id="Td2" runat="server" style="">SignalID:
Asset:
<asp:TextBox ID="AssetTextBox" runat="server" ReadOnly="true" Text='<%# Bind("Asset") %>' />
<br />
SignalDate:
<asp:TextBox ID="SignalDateTextBox" runat="server" Text='<%# Bind("SignalDate") %>' />
<br />
Direction:
<asp:TextBox ID="DirectionTextBox" runat="server" Text='<%# Bind("Direction") %>' />
<br />
StrikePrice:
<asp:TextBox ID="StrikePriceTextBox" runat="server" Text='<%# Bind("StrikePrice") %>' />
<br />
ExpiryPrice:
<asp:TextBox ID="ExpiryPriceTextBox" runat="server" Text='<%# Bind("ExpiryPrice") %>' />
<br />
StartTime:
<asp:TextBox ID="StartTimeTextBox" runat="server" Text='<%# Bind("StartTime") %>' />
<br />
ExpiryTime:
<asp:TextBox ID="ExpiryTimeTextBox" runat="server" Text='<%# Bind("ExpiryTime") %>' />
<br />
Result:
<asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="Outcome" DataTextField="Result" DataValueField="ResultID" SelectedValue='<%#Bind("ResultID") %>'></asp:DropDownList>
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<br />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
<br />
</td>
</EditItemTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<EmptyItemTemplate>
<td id="Td3" runat="server" />
</EmptyItemTemplate>
<GroupTemplate>
<tr id="itemPlaceholderContainer" runat="server">
<td id="itemPlaceholder" runat="server"></td>
</tr>
</GroupTemplate>
<InsertItemTemplate>
<td id="Td4" runat="server" style="">Asset:
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="Assets" DataTextField="Asset" DataValueField="AssetID" AutoPostBack="True" SelectedValue='<%# Bind("AssetID") %>'>
</asp:DropDownList>
<br />
SignalDate:
<asp:Label ID="SignalDateLabel" runat="server" Text='<%# Bind("SignalDate") %>' />
<br />
Direction:
<asp:TextBox ID="DirectionTextBox" runat="server" Text='<%# Bind("Direction") %>' />
<br />
StrikePrice:
<asp:TextBox ID="StrikePriceTextBox" runat="server" Text='<%# Bind("StrikePrice") %>' />
<br />
ExpiryPrice:
<asp:TextBox ID="ExpiryPriceTextBox" runat="server" Text='<%# Bind("ExpiryPrice") %>' />
<br />
StartTime:
<asp:TextBox ID="StartTimeTextBox" runat="server" Text='<%# Bind("StartTime") %>' />
<br />
ExpiryTime:
<asp:TextBox ID="ExpiryTimeTextBox" runat="server" Text='<%# Bind("ExpiryTime") %>' />
<br />
Result:
<asp:TextBox ID="ResultTextBox" runat="server" Text='<%# Bind("Result") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<br />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
<br />
</td>
</InsertItemTemplate>
<ItemTemplate>
<td id="Td5" runat="server" style="">SignalID:
<asp:Label ID="SignalIDLabel" runat="server" Text='<%# Eval("SignalID") %>' />
<br />
Asset:
<asp:Label ID="AssetLabel" runat="server" Text='<%# Eval("Asset") %>' />
<br />
SignalDate:
<asp:Label ID="SignalDateLabel" runat="server" Text='<%# Eval("SignalDate","{0:yyyy-MM-dd}") %>' />
<br />
Direction:
<asp:Label ID="DirectionLabel" runat="server" Text='<%# Eval("Direction") %>' />
<br />
StrikePrice:
<asp:Label ID="StrikePriceLabel" runat="server" Text='<%# Eval("StrikePrice") %>' />
<br />
ExpiryPrice:
<asp:Label ID="ExpiryPriceLabel" runat="server" Text='<%# Eval("ExpiryPrice") %>' />
<br />
StartTime:
<asp:Label ID="StartTimeLabel" runat="server" Text='<%# Eval("StartTime") %>' />
<br />
ExpiryTime:
<asp:Label ID="ExpiryTimeLabel" runat="server" Text='<%# Eval("ExpiryTime") %>' />
<br />
Result:
<asp:Label ID="ResultLabel" runat="server" Text='<%# Eval("Result") %>' />
<br />
ResultID:
<asp:Label ID="ResultIDLabel" runat="server" Text='<%#Eval("ResultID") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td6" runat="server">
<table id="groupPlaceholderContainer" runat="server" border="0" style="">
<tr id="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr2" runat="server">
<td id="Td7" runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<td id="Td8" runat="server" style="">SignalID:
<asp:Label ID="SignalIDLabel" runat="server" Text='<%# Eval("SignalID") %>' />
<br />
AssetID:
<asp:Label ID="AssetIDLabel" runat="server" Text='<%# Eval("AssetID") %>' />
<br />
Asset:
<asp:Label ID="AssetLabel" runat="server" Text='<%# Eval("Asset") %>' />
<br />
SignalDate:
<asp:Label ID="SignalDateLabel" runat="server" Text='<%# Eval("SignalDate","{0:yyyy-MM-dd}") %>' />
<br />
Direction:
<asp:Label ID="DirectionLabel" runat="server" Text='<%# Eval("Direction") %>' />
<br />
StrikePrice:
<asp:Label ID="StrikePriceLabel" runat="server" Text='<%# Eval("StrikePrice") %>' />
<br />
ExpiryPrice:
<asp:Label ID="ExpiryPriceLabel" runat="server" Text='<%# Eval("ExpiryPrice") %>' />
<br />
StartTime:
<asp:Label ID="StartTimeLabel" runat="server" Text='<%# Eval("SignalDate") %>' />
<br />
ExpiryTime:
<asp:Label ID="ExpiryTimeLabel" runat="server" Text='<%# Eval("ExpiryTime") %>' />
<br />
Result:
<asp:Label ID="ResultLabel" runat="server" Text='<%# Eval("Result") %>' />
<br />
ResultID:
<asp:Label ID="ResultIDLabel" runat="server" Text='<%# Eval("ResultID") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="Assets" runat="server" ConnectionString="<%$ ConnectionStrings:Signals2UConnectionString %>" SelectCommand="SELECT [AssetID], [Asset], [AssetType], [Symbol] FROM [Assets]"></asp:SqlDataSource>
<asp:SqlDataSource ID="times" runat="server" ConnectionString="<%$ ConnectionStrings:Signals2UConnectionString %>" SelectCommand="SELECT DISTINCT [TimeID], [TimeValues] FROM [Times]"></asp:SqlDataSource>
<asp:SqlDataSource ID="Outcome" runat="server" ConnectionString="<%$ ConnectionStrings:Signals2UConnectionString %>" SelectCommand="SELECT [ResultID], [Result] FROM [Results]"></asp:SqlDataSource>
</div>
I try to update the Results value which is a Foreign key stored in the Binary Signals table coming from the Results table. Result field is used as the display text and the ResultId as the value for the dropdown list
Solved. The below was missing from the EditItemTemplate
<asp:Label ID="SignalIDLabel" runat="server" Text='<%# Bind("SignalID")%>'/>
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>
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);
}
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.