I have only found posts in which people using gridviews and modal popups need help with editing. However, I am not using a gridview so editing is not as simple as an edit within a gridview. The modal popup disappears when I click on the edit button. Here is what I have so far, but in the codebehind I get an error saying that my modal isn't declared.
In the image below, the little pencil image next to the close button is what I click on to edit the description. When I click on it, the modal disappears, so I cannot edit the text.
<!-- Descriptions -->
<asp:TabPanel ID="tab2" runat="server" HeaderText="Descriptions">
<HeaderTemplate>Descriptions</HeaderTemplate>
<ContentTemplate>
<ul class="info">
<asp:ListView ID="lvDescriptions" runat="server"
DataSourceID="dsAdminMarketingDescriptions" DataKeyNames="MarketingID">
<ItemTemplate>
<li class="item">
<asp:LinkButton ID="ViewDescriptionButton" runat="server"><%#
Eval("Title")%>
</asp:LinkButton>
<asp:ImageButton ID="DeleteDescriptionButton" runat="server"
Style="float:right;" AlternateText=""
ImageUrl="../../images/delete.png" CommandName="Delete"
OnClientClick="return confirm('Are you sure you want to delete this
description?')" />
<asp:Panel ID="ViewDescriptionPanel" runat="server"
CssClass="DescModalPopup">
<div class="PopupHeader">View Description -- <%#Eval("Title") %>
<asp:ImageButton ID="CancelDescriptionButton" runat="server"
ImageUrl="../../images/cancel.png" AlternateText=""
Style="float:right;"/>
<asp:ImageButton ID="EditDescriptionButton" runat="server"
ImageUrl="../../images/edit.png" AlternateText=""
Style="float:right;" CommandName="edit" AutoPostBack="false" />
</div>
<asp:Label ID="Description" runat="server" style="padding:2px;">
<%# Eval("Data")%>
</asp:Label>
</asp:Panel>
<asp:ModalPopupExtender ID="ViewDescriptionModal" runat="server"
BackgroundCssClass="modalBackground" DropShadow="false"
DynamicServicePath="" Enabled="true"
PopupControlID="ViewDescriptionPanel"
TargetControlID="ViewDescriptionButton"
CancelControlID="CancelDescriptionButton">
</asp:ModalPopupExtender>
</li>
</ItemTemplate>
Protected Sub EditDescriptionButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
ViewDescriptionModal.Show()
End Sub
UPDATE: i changed the codebehind, but I still get an error saying ViewDescriptionModal is not declared.
Protected Sub EditDescriptionButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myControl As Control = FindControl("ViewDescriptionModal")
If (Not myControl Is Nothing) Then
ViewDescriptionModal.Show()
Else
'Control not found
End If
End Sub
UPDATE: I have created a second modal popup for edits and changed the Label to a Textbox to pull in information from the database to edit. I added a submit button, but when I click on it, I get an error saying something about it being potentially dangerous.
Does anyone have any experience with A potentially dangerous Request.Form value was detected from the client
I haven't tested this, but you may have luck if you use two modalpopupextenders, and two panels, one for viewing and one for editing.
<asp:ModalPopupExtender ID="ViewDescriptionModal" runat="server"
BackgroundCssClass="modalBackground" DropShadow="false"
DynamicServicePath="" Enabled="true"
PopupControlID="ViewDescriptionPanel"
TargetControlID="ViewDescriptionButton"
CancelControlID="CancelDescriptionButton">
</asp:ModalPopupExtender>
<asp:ModalPopupExtender ID="EditDescriptionModal" runat="server"
BackgroundCssClass="modalBackground" DropShadow="false"
DynamicServicePath="" Enabled="true"
PopupControlID="EditDescriptionPanel"
TargetControlID="EditDescriptionButton">
</asp:ModalPopupExtender>
<asp:Panel ID="ViewDescriptionPanel" runat="server" ... </asp:panel>
<asp:Panel ID="EditDescriptionPanel" runat="server" ... </asp:Panel><code>
try in your image button autopostback="false"
Related
Here's an update panel with triggers:
<asp:UpdatePanel runat="server" ID="UpdatePanel1" ChildrenAsTriggers="true">
<ContentTemplate>
<p> Much wow! </p>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID='x' EventName="Command" />
</Triggers>
</asp:UpdatePanel>
This is my repeater (NOT INSIDE THE UPDATE PANEL):
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="x" OnCommand="x_command" runat="server" CommandArgument='<%#Eval("y") %>'>
</ItemTemplate>
</asp:Repeater>
I am unable to find the controlID of the linkbutton.
I've tried registering the control, the control gets registered but the updatepanel still cannot find the control.
Code to register control-
Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
Dim lb As LinkButton = TryCast(e.Item.FindControl("dude1"), LinkButton)
ScriptManager.GetCurrent(Me).RegisterAsyncPostBackControl(lb)
Response.Write("afa")
End Sub
I just realized- all I didn't have to do was define the button as trigger in the update panel.
When you register it as an asyncpostback control, it already acts as a trigger.
Hope this helps anyone that got stuck.
I have an AsyncFileUpload control in a detailsview. I can browse to select a file to upload. When I start the upload the OnClientUploadComplete function uploadRoomThumbComplete method is executed, but the function in OnUploadedComplete is never hit.
Why?
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DetailsView AutoGenerateRows="False" DefaultMode="Edit" Width="100%" DataKeyNames="id" DataSourceID="odsDetails" ID="dvOfferDetails" runat="server">
<Fields>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderStyle-VerticalAlign="Bottom" HeaderText="<%$Resources:Glossary,image%>">
<EditItemTemplate>
<asp:literal ID="ltImage" runat="server" />
<p id="RoomContainer">
</p>
<asp:literal ID="ltDeleteRoomThumb" runat="server" />
<cc1:AsyncFileUpload CssClass="imageUploaderField" ID="afuRoomThumb" Width="150" runat="server" ClientIDMode="AutoID" OnUploadedComplete="afuRoomThumb_UploadedComplete" OnClientUploadComplete="uploadRoomThumbComplete" />
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</ContentTemplate>
</asp:UpdatePanel>
Protected Sub afuRoomThumb_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs)
'---> this codeblock is NEVER hit....why?
End Sub
Ok, I found the answer here: http://forums.asp.net/t/1477331.aspx?AsyncFileUpload+inside+a+GridView+inside+an+UpdatePanel
In short: place another AsyncFileUpload control on the page and set the style's display:none.
It seems that the AsyncFileUpload is designed to be used only once on a page, and when you put it on your master page, any afu inside an updatepanel will work.
I have the following DetailsView defined with a DropDownList of data and an Add ButtonField:
<asp:DetailsView ID="dvNewEntry" runat="server" Height="50px" Width="800px"
AutoGenerateRows="False" CssClass="gv_footer" BorderColor="Black"
BorderStyle="Solid" BorderWidth="2px" CellPadding="5" CellSpacing="8">
<FieldHeaderStyle CssClass="th_right" />
<Fields>
<asp:TemplateField HeaderText="Account Name">
<ItemTemplate>
<asp:Label ID="lblNewAcct" runat="server" Text='<%# Eval("ACCT_LIST") %
>'></asp:Label>
</ItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="ddAcctList" runat="server" DataSourceID="LUWAcctList"
DataTextField="ACCT_LIST" DataValueField="ACCT_LIST"
SelectedValue='<%# Bind("ACCT_LIST") %>' Font-Size="Small" Width="600">
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Button" Text="Save" CommandName="Add"/>
</Fields>
</asp:DetailsView>
In the codebehind - I have the following ItemCommand sub.
Protected Sub dvNewEntry_ItemCommand(ByVal sender As Object, ByVal e As DetailsViewCommandEventArgs) Handles dvNewEntry.ItemCommand
If e.CommandName = "Add" Then
Dim newA As String
newA = Trim(CType(dvNewEntry.FindControl("ddAcctList"), DropDownList).Text)
etc. etc.
Everything works fine when the user selects a value from the dropdown list. But if they don't make a selection and click the Add button - I get the following error when I land on the "If e.CommandName = Add" line:
Index was outside the bounds of the array
How do I handle this exception? Thanks
If (e.[someproperty] IsNot Null) Then --> your code solved the problem. Thanks Tanner
I have a form on an asp.net (VB) page which has 2 sections.
All of section 1 is always required, but section 2 is optional. However, if section 2 is started, then all fields are required.
I'm stuck as to the logic I need to create this validation.
Here's my code:
<form runat="server">
<div>
<asp:TextBox runat="server" ID="field1a" Text="Name" />
<asp:TextBox runat="server" ID="field1b" Text="City" />
<asp:RequiredFieldValidator runat="server" ID="field1aVal" Text="Name Required" ControlToValidate="field1a" InitialValue="Name" />
<asp:RequiredFieldValidator runat="server" ID="field1bVal" Text="City Required" ControlToValidate="field1b" InitialValue="City" />
</div>
<div>
<asp:TextBox runat="server" ID="field2a" Text="Name" />
<asp:TextBox runat="server" ID="field2b" Text="City" />
<asp:RequiredFieldValidator runat="server" ID="field2aVal" Text="Name Required" ControlToValidate="field2a" InitialValue="Name" />
<asp:RequiredFieldValidator runat="server" ID="field2bVal" Text="City Required" ControlToValidate="field2b" InitialValue="City" />
</div>
<asp:button runat="server" ID="btnSubmit" Text="Submit" OnClick="submitForm" />
</form>
Id say use required fields on section 1, but for section two use a custom validator. Something like this.
<asp:CustomValidator ID="CustomValidator2" runat="server"
Display="Dynamic" EnableClientScript="False"
ErrorMessage="You must select one checkbox or click all offices. " OnServerValidate="OfficeVaildator">
</asp:CustomValidator>
Then in code behind do your logic
Something like this
Sub OfficeVaildator(ByVal source As Object, ByVal args As ServerValidateEventArgs)
If OfficeCheckBoxs.Checked Then
args.IsValid = True
Else
args.IsValid = False
End If
End Sub
Obviously that is really simple. You would want to check if the user altered section 2 in anyway, and if he did make him complete all fields to return your server validation arguments true. If he didnt alter section 2 or give it any data right a method that checks that and set your validation to true to allow him to proceed.
I have a popup login usercontrol in a masterpage, once logged in I want another usercontrol on a content page to appear automatically, currently it only appears if I manually refresh the page. How can this be accomplished. Thanks.
MasterPage - > login usercontrol
View.aspx - > bookmark usercontrol (should appear after logging in)
login usercontrol in Master Page
<asp:UpdatePanel ID="login" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlLogin" runat="server">
<asp:TextBox ID="txtpassword" runat="server" TextMode="Password </asp:TextBox>
<asp:Button ID="btbookmark" runat="server" Text="Login" OnClick="btbookmark_Click"/>
</asp:Panel>
<asp:Panel ID="pnlData" runat="server">Placeholder for bookmark data. Bookmark data goes here.
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Bookmark usercontrol on View.aspx
<asp:TextBox ID="txtbookmark" runat="server"></asp:TextBox><br />
<asp:Button ID="btmark" runat="server" />
After logging in how can the Bookmark usercontrol on View.aspx appear. Do I need to use an updatepanel?
You could either register it and set the Visible property to false in the code behind, until the user has logged in, and then you set the property to true. You will need to add code to prevent a lot of processing if the user session object doesn't exist.
aspx:
<%# Register TagPrefix="control" TagName="UserBookmarks" Src="~UserBookmarks.ascx" %>
<control:UserBookMarks ID="UserBookmarksCtrl" runat="server" Visible="false" />
code behind:
// If user logged in
UserBookmarksCtrl.Visible = True
Or, you can dynamically create the control, and add it to your page once a user has logged in (i.e. something like Session["user"] has been set).