|
-
Feb 27th, 2005, 07:57 AM
#1
Thread Starter
Fanatic Member
accessing file input while in edit mode of datalist
Hey All i am building an image gallery and i have used a datalist for repeating all the itmes in the gallery, when i want to update an image i have stuck a html:file input within the edit region of the datalist
How can i access the fileInput in the code behind
VB Code:
If Len(Me.FileUpload.Value) <> 0 Then
objFile.Upload(Me.FileUpload.PostedFile)
objFile.Resize()
strFileName = objFile.NewFileName
Else
strFileName = "NA.gif"
End If
When the fileInput control is in the datalist how do i access it ?
thanks in advance
Carl
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Mar 1st, 2005, 11:22 AM
#2
Frenzied Member
Re: accessing file input while in edit mode of datalist
Well first you need button of some kind to postback the page and hence upload the file.
Best thing to do is use a simple button and set its CommandName to "Update". You can then use the UpdateCommand event to fire a method that will process the upload. You'll need to set the OnUpdateCommand property for the datalist to point to the right method.
Inside the UpdateCommand method you first need to grab the HtmlInputFile into a local variable using the DataListCommandEventArgs passed into the method and the FindControl method that will find the file upload by its control's ID. You can then check if a file was uploaded and process it accordingly.
In C# this would be roughly:
Code:
void blah_UpdateCommand(Object sender, DataListCommandEventArgs e) {
HtmlInputFile filupload = (HtmlInputFile) e.Item.FindControl("upload");
if (filupload.PostedFile.ContentLength > 0) {
// A file has been uploaded.
}
}
<datalist id="blah" OnUpdateCommand="blah_UpdateCommand">
<ItemTemplate>
Stuff in here...
</ItemTemplate>
<EditItemTemplate>
<input type="file" id="upload" />
<asp:Button id="update" CommandName="Update" Text="UPDATE!" />
</EditItemTemplate>
</datalist>
Hope that makes sense.
DJ
-
Mar 2nd, 2005, 03:05 AM
#3
Thread Starter
Fanatic Member
Re: accessing file input while in edit mode of datalist
nice one DJ
It works like a dream thank you very much
Carl
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Mar 2nd, 2005, 03:16 AM
#4
Thread Starter
Fanatic Member
Re: accessing file input while in edit mode of datalist
DJ if i wanted to make a button visible / invisiable within the page load event
how would i set the DataListCommandEventArgs because the e is already decalred on the System.EventArgs
basically i only want administrators of the site to be able to edit content
so i was thinking when they log in i set a session variable with the users rights and when i load a page i check the session to see if its an administrator if so then i make the edit button visiable
some thing like
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'hide all the administration buttons
If Session.Item("URights") = 1 Then
Dim btnEdit As Button '= now i have to find the control
End If
If Not Page.IsPostBack Then
loadarticle()
End If
End Sub
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Mar 2nd, 2005, 05:28 AM
#5
Frenzied Member
Re: accessing file input while in edit mode of datalist
As the control is in an databound control you need to set the edit button visible/hidden during databinding not on page load.
Try:
Code:
<ItemTemplate>
<asp:Button id="btnEdit" runat="server" Text="EDIT!" CommandName="Edit" Visible=<%# Session.Item("URights") = 1 %> />
</ItemTemplate>
This will set the visible property to true or false on DataBind. Be careful with the quotes notice there aren't any around the data bound expression.
HTH
DJ
-
Mar 2nd, 2005, 08:23 AM
#6
Thread Starter
Fanatic Member
Re: accessing file input while in edit mode of datalist
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|