I have the following asp repeater:
<asp:Repeater runat="server" ID="rptResults">
<ItemTemplate>
<div class="FileFile Large pdf SearchResult" id="<%# DirectCast(Container.DataItem, FileFolder).DocStoreID%>">
<a href='<%# DirectCast(Container.DataItem, FileFolder).Link %>' style="text-decoration:none">
<%# DirectCast(Container.DataItem, FileFolder).BackgroundHTML%>
<p style="float:left;line-height:32px;margin:0px"><%# DirectCast(Container.DataItem, FileFolder).Filename%></p>
</a>
<asp:Button runat="server" OnClientClick="return confirmation(this);" ID="btnDeleteFile" CommandArgument="<%# DirectCast(Container.DataItem, FileFolder).DocStoreID%>" UseSubmitBehavior="false" Text="Delete" Style="float:right;margin-top:8px;cursor:pointer;"/>
<a style="float:right;line-height:32px;margin-right:10px">ID = <%# DirectCast(Container.DataItem, FileFolder).DocStoreID%></a>
</div>
</ItemTemplate>
</asp:Repeater>
<script>
function confirmation(sender) {
if (confirm("Delete file "+ sender.id + "?"))
return true;
else return false;
}
</script>
I want the OnClientClick to say:
Delete File ######
to do this I need to pass in the id of the parent div, or the content of the <a> next to it.
Currently, I have OnClientClick="return confirmation(this);", which passes in the button. SO I could possibly store this information in a field on the button, but I have tried:
name="%# DirectCast(Container.DataItem, FileFolder).DocStoreID%>"
But this does not work. Are there any other variables I can use to store this, or a way to pass a reference to another element within the repeater?
you can use title attribute in your button:
title="<%# DirectCast(Container.DataItem, FileFolder).DocStoreID%>"
and then your javascript will be
function confirmation(sender){
if(confirm("Delete file " + sender.title + " ?"))
return true;
else
return false;
}
be aware that title attribute is intended to display a tooltip, so the user will see a toolip over your button. Hope it helps.
Try this
OnClientClick="return confirmation('<%= DirectCast(Container.DataItem, FileFolder).DocStoreID %>');"
And you JS would be
function confirmation(sender) {
if (confirm("Delete file "+ sender + "?"))
return true;
else return false;
}
Related
I have check.aspx file which has:
<%# MasterType VirtualPath="~/MSW.master" %>
And in this master file I have:
<%# Register Src="UserControls/Common/StatusBar.ascx" TagName="StatusBar" TagPrefix="uc3" %>
And in this StatusBar.ascx, I have a div:
<div id="status_box_content">
<asp:Label ID="lblWelcome" runat="server" Text="Welcome " ></asp:Label>
<asp:Label ID="lbUser" runat="server"meta:resourcekey="lblFullNameResource1"></asp:Label>
<asp:Label ID="lblPartnerInfo" runat="server" ></asp:Label>
<asp:HyperLink Font-Underline="False" NavigateUrl="~/profile/Logout.aspx"
ID="HLinkLogout" runat="server" meta:resourcekey="HLinkLogoutResource1">Logout</asp:HyperLink>
</div>
I want this div with id ="status_box_content" to be invisible in check.aspx file. But everything else from master file is needed.
How do I make the div invisible while keeping the master file?
In your check.aspx, hide the div using jquery. It works perfectly fine. I was making a huge mistake while calling it.So yeah,it works! :)
Notes: Make your div runat="server"
Aspx Page
<div id="status_box_content" runat="server">
<asp:Label ID="lblWelcome" runat="server" Text="Welcome " ></asp:Label> <asp:Label ID="lbUser" runat="server"meta:resourcekey="lblFullNameResource1"></asp:Label>
<asp:Label ID="lblPartnerInfo" runat="server" ></asp:Label>
<asp:HyperLink Font-Underline="False" NavigateUrl="~/profile/Logout.aspx"
ID="HLinkLogout" runat="server" meta:resourcekey="HLinkLogoutResource1">Logout</asp:HyperLink>
</div>
Code Behind Page : Put This Code in your content page_load event
HtmlGenericControl DivCount = (HtmlGenericControl)Page.Master.FindControl("status_box_content");
DivCount.Visible = false;
Make runat= server to your div.
And then on page load of check.aspx use make that div invisible:
this.Master.findcontrol("divname").visible= false;
As the div is inside UserControl and User Control is inside Master Page, just try to access UserControl First in your page, then find out div and make it invisible. You could try out this:
First make the div as server control,Add runat="server" in div :
<div id="status_box_content" runat="server">
UserControl uc = ((UserControl)this.Master.FindControl("ucTopUser"));
HtmlGenericControl div = (HtmlGenericControl )uc.FindControl("status_box_content");
div.Visible = false;
I'd like to get some help on an issue I'm having. I have a stored procedure that returns a dataset to fill a datagriview. One of the data grid's columns contains 2 manually set buttons, 'View' & 'Add'. These buttons open up a new popup window which displays extra information etc. I would like to be able to hide a 'View' button if 1 of the returned parameter's, POCount, count is equal to 0. i.e. there is nothing to view for that row. What is the best way to make this happen.
My stored procedure is
SELECT PM.ProjectCode,
PM.ProjectDesc,
PM.Active,
PM.Chargeable,
(SELECT COUNT(*) FROM POMaster PO WHERE PO.ProjectCode = PM.ProjectCode) AS POCount
FROM PROJECTMASTER PM
Front End Code
<asp:TemplateField HeaderText="P.O. Number" ItemStyle-Wrap="false" >
<ItemTemplate>
<asp:LinkButton ID="linkPONumber" runat="server" Text="View" CssClass="buttonStyle" OnClick="LinkPONumber_Click" CommandArgument='<%# Eval("ProjectCode") + ";" + Eval("ProjectDesc") %>' ></asp:LinkButton>
<asp:LinkButton ID="linkAddPO" runat="server" Text="Add" CssClass="buttonStyle" OnClick="LinkAddPO_Click" CommandArgument='<%# Eval("ProjectCode") + ";" + Eval("ProjectDesc") %>' ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Code Behind
private void BindGrid()
{
DSProjectDetails = objProjectMasterBL.GetProjectDetails();
GvProject.DataSource = DSProjectDetails;
GvProject.DataBind();
}
public DataSet GetProjectDetails()
{
try
{
SqlProcedureName = "USP_GetProjectListWithPO";
SqlConnectionObject = DBConnection.InitializeConnection(SqlConnectionObject);
dsrepeater = SqlHelper.ExecuteDataset(SqlConnectionObject, CommandType.StoredProcedure, SqlProcedureName);
return dsrepeater;
}
catch (Exception ex)
{
log.Error("Exception in ProjectMasterBL.GetProjectDetails:", ex);
throw ex;
}
}
Apologies if I've sent the wrong sections of code, still residing in the noob ranks
You can use the Visible property of Link Button:-
<asp:LinkButton ID="linkAddPO" runat="server" Text="Add" CssClass="buttonStyle"
OnClick="LinkAddPO_Click" Visible='<%# Convert.ToInt32(Eval("POCount")) == 0 %>'
CommandArgument='<%# Eval("ProjectCode") + ";" + Eval("ProjectDesc") %>'>
</asp:LinkButton>
Whenever your SP returns POCount as 0, you LinkButton will be hidden.
I have an image inside an updatepanel. When I click on the image it needs to be highlighted. I use addclass and removeclass to make this work, if it is outside updatepanel. When I put the image inside the updatepanel, the css is applied but then reverts to original after the update completes and the page is rendered.
How can I change the styling of the image inside the updatepanel dynamically?
Markup:
<asp:UpdatePanel ID="UpdatePanel2" runat="server" class="journey-categories">
<ContentTemplate>
<ul class="journey-categories">
<asp:Repeater ID="rptJourneyCategories" runat="server">
<ItemTemplate>
<li>
<a href="javascript:void(0)" data-categoryid="<%# Eval("Id") %>" data-introtitle="<%# Eval("IntroTitle") %>" data-introtext="<%# Eval("IntroText") %>">
<img class="thumb" src="<%# Eval("CategoryIcon") %>" width="70" height="70" alt="" id="imgCategoryIcon" />
</a>
<span><%# Eval("Title") %></span>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</ContentTemplate>
</asp:UpdatePanel>
Jquery:
$('[data-categoryid]').off('click.categories').on('click.categories', function () {
$(this).closest('ul').find('li.selected').removeClass('selected');
$(this).parent().addClass('selected');
});
I got this to work with the help of EndRequestHandler
I added the following inside script document ready and it updated the styling after the update panel completed.
<script type="text/javascript">
$(function () {
var onDomReady = function () {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler() {
var type = $('[id$=ddlType]').val();
$('a[data-categoryid="' + type + '"').parent().addClass('selected');
}
}});
I need help with getting the ID of the Control in RadGrid in order to set it Visable=False.
The last function is actually creating a pic based on the value that's coming from the DB. How can I set the HyperLink next to the Pic that I'm adding to Visible false?
I think that I need to send that function RenderLinked the hyperlink control but I don't know how and I hope that some one can show me the way.
<telerik:RadGrid
ID="rgPhoneBook"
runat="server"
AutoGenerateColumns="False"
AllowPaging="True"
AllowSorting="True"
PageSize="50"
CellSpacing="0" GridLines="None"
OnItemCommand="rgPhoneBook_ItemCommand"
OnPageIndexChanged="rgPhoneBook_OnPageIndexChanged"
OnSortCommand="rgPhoneBook_OnSortCommand"
OnItemCreated="rgPhoneBook_OnItemCreated"
EnableHeaderContextFilterMenu="True"
Width="933px"
Height="528px">
<ClientSettings>
<Selecting AllowRowSelect="True"></Selecting>
<Scrolling AllowScroll="true" UseStaticHeaders="True" SaveScrollPosition="true" FrozenColumnsCount="2" />
</ClientSettings>
<MasterTableView ShowHeadersWhenNoRecords="true" NoMasterRecordsText="No PhoneBook Records to display" Font-Size="11px" GridLines="None" AllowPaging="True" ItemStyle-Height="25px" CommandItemDisplay="Top" AllowAutomaticUpdates="False" TableLayout="Auto" DataKeyNames="LocationID,PersonID" ClientDataKeyNames="LocationID,PersonID">
<PagerStyle Mode="NumericPages"></PagerStyle>
<Columns>
<telerik:GridTemplateColumn HeaderText="Linked" HeaderStyle-Width="45px" >
<ItemTemplate>
<span id="spanHyperLink" style="visibility:visible" runat="server">
<asp:HyperLink ID="Link" runat="server" Text="Link">
</asp:HyperLink>
</span>
<%# RenderLinked(DataBinder.Eval(Container.DataItem, "Linked"))%>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
Protected Function RenderLinked(ByVal inputVal As String) As String
Dim output As String = ""
Try
Dim svcs As New SystemServices
If Not inputVal Is Nothing And Not String.IsNullOrEmpty(inputVal) Then
If inputVal = True Then
output = "<img src='" + Globals.gRootRelativeSecureURL("\Images\Layout\Link.png") + "' width=""13"" height=""13"" border=""0"" align=""absmiddle"">"
Else
'Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
'Dim link As HyperLink = DirectCast(item("Link").Controls(0), HyperLink)
'LinkButton.DisabledCssClass = True
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "StartupScript", "Sys.Application.add_load(function() { DisableHyperLinkCSS(); });", True)
'output = "<a herf='#' onclick='showPersonLinkModal() ;'>Link</a>"
End If
End If
Catch ex As Exception
Globals.SendEmailError(ex, m_User.SessionID, System.Reflection.MethodBase.GetCurrentMethod.Name.ToString(), Request.RawUrl.ToString(), m_User.UserID)
End Try
Return output
End Function
If you want to set some control's attribute visible=false in code behind when rows are bound to data 1 by 1 you may use RowDataBound event and write following code in it's handler
Control_Type Control_ID = (Control_Type) e.Row.FindControl("Control_ID");
Control_ID.Visible = false;
And if you want to set it in javascript,
rgPhoneBook.Rows[Record_Index].Cells[0].Visible = false;
Hope this helps you. The above code is in C#, please convert it to it's equivalent in VB.
I have a text box using cc1:Editor and when I place a required field validator on it, it displays as soon as the page loads. How can I hide the error and allow it to display only if the html editor box is empty?
<code><cc1:Editor ID="txtDescription" Width="500px" Height="525px"
runat="server" TextMode="SingleLine" /></code>
<code>
<asp:RequiredFieldValidator ID="rfvDescription" runat="server"
ControlToValidate="txtDescription"
ErrorMessage="Must include Description" Font-Bold="True"></asp:RequiredFieldValidator>
</code>
<code><asp:Button ID="SubmitBtn" runat="server"
Text="Submit" OnClick="SubmitBtn_Click" class="form-td" Height="30px" />
<script language="javascript" type="text/javascript">
document.onkeypress = keyhandler;
function keyhandler(e) {
Key = window.event.keyCode; if (Key == 13) {
var obj = document.getElementById('<%=SubmitBtn.ClientID%>');
obj.focus();
obj.click();
}
}
</script>
Yes, you can perform custom validation on your submit button client side & server side validation on your postback event thus removing required field validator. Check following example:
On your aspx page
<p>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:return ValidateEditor();"
ValidationGroup="myGroup" onclick="Button1_Click" />
<br />
</p>
<asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label>
<cc1:Editor ID="Editor1" runat="server" />
<script type="text/javascript">
function ValidateEditor() {
var txtEditor = $find('<%=Editor1.ClientID %>');
if (txtEditor.get_content() == null || txtEditor.get_content() == '') {
alert('Text cannot be empty');
document.getElementById('<%=lblMessage.ClientID %>').innerHTML='Text cannot be empty';
return false;
}
else
return true;
}
</script>
On server side
if (string.IsNullOrEmpty(Editor1.Content.ToString()))
{
lblMessage.Text = "Text cannot be empty";
}
else
{
// Do your work here
}