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');
}
}});
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 am trying to build a three level left navigation for my application using asp.net repeater and html list
I have three nested repeater with a linkbutton inside
when i click the linkbutton the list class should be active ( i have css for this active class).I am not good in Jquery
below is my code ( now i used only two repeater),Kindly help me how can i do this?
<ul class="nav nav-list mb-xl show-bg-active">
<asp:repeater ID="rep1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<li class="">
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("Menu") %>'></asp:LinkButton>
<asp:repeater ID="rep2" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<ul>
<li>
<asp:LinkButton ID="LinkButton2" CommandArgument="id" runat="server" Text='<%# Eval("Menu") %>'></asp:LinkButton>
</li> </ul>
</ItemTemplate>
</asp:repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KTCWEBConnectionString %>" SelectCommand="SELECT NAVIAGATE_1.Menu FROM NAVIAGATE INNER JOIN NAVIAGATE AS NAVIAGATE_1 ON NAVIAGATE.ID = NAVIAGATE_1.ParentID WHERE (NAVIAGATE.Menu = #menu)">
<SelectParameters>
<asp:ControlParameter ControlID="LinkButton1" Name="menu" PropertyName="text" />
</SelectParameters>
</asp:SqlDataSource>
</li>
</ItemTemplate>
</asp:repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KTCWEBConnectionString %>" SelectCommand="SELECT DISTINCT Menu, ParentID, ID FROM NAVIAGATE WHERE (NOT (ParentID IS NULL)) AND (ParentID = 2)"></asp:SqlDataSource>
</ul>
So it's been a while since I've done ASP.Net controls but...
Your inner lists would need to bind the Enabled property to something in your Controller. Then when something is clicked you just set that binding to false. This should in turn disable all those buttons and if your css is written correctly (tier2:disabled) it should pick it up correctly.
That said, if this is a new application, stop using ASP.NET controls, it should have been killed a long time ago. HTML + CSS + ReactJs or KnockoutJs is the way to go now-a-days!
I want to pass the variable from html page to a hidden field in aspx page, I have a aspx form with code
<div id="divFrameHolder" style="display: none">
<iframe src="inner/RegSelect.html"name="myIframe" id="myIframe" width="100%" height="200px" frameborder="0" onload="hideLoading()">
<asp:HiddenField ID = "hidField" runat="server" value = " " />
</iframe>
</div>
and RegSelect.html has this code
<div id="tabs">
<ul>
<li style="font-family:'b nazanin'; font-weight:bold"><a onclick="use();" href="site"><i class="fa fa-picture-o fa-5x"></i><br />سایت</a></li>
<li style="font-family: 'b nazanin'; font-weight: bold"><a onclick="use();" href="stor"><i class="fa fa-shopping-cart fa-5x"></i><br />فروشگاه</a></li>
<li style="font-family: 'b nazanin'; font-weight: bold"><a onclick="use();" href="blog"><i class="fa fa-comments fa-5x"></i><br />وبلاگ</a></li>
</ul>
<section class="tabs-content" style="width:100%">
<div id="site" style="width:100%" >
</div>
<div id="stor">
</div>
<div id="blog">
</div>
</section>
</div>
<script>
$('#tabs a').click(function (e) {
var f = $(this).attr('href');
alert(f);
window.opener.location.href = "RegForm.aspx?" + "val=" + f
//var c = $('#myIframe').contents().find('#HF1').val();
//alert(c);
//alert($('#myIframe #HF1').val());
//$(' #HF1').val(f);
});
</script>
Now, I want get var f in aspx page? Can I get the variable from html page into aspx page?
You can use Request.QueryString to get the value of an URL parameter
Retrieve GET variables from URL in ASPX
Seems like you want to pass a variable from the html page in the IFrame to a hidden field in the page containing the IFrame.
Accessing IFrame content using jQuery as explained here: how to access iFrame parent page using jquery?
Note: ASP.NET WebForms has a setting that determines how ID's are generated for a control. See Here Make sure your hidden field's id mode is static.
Also understand that ASP.NET generates ID's to prevent collisions. Use an ID for your hidden field that you know will be unique on the page.
<asp:HiddenField ID="hidField" ClientIDMode="Static" runat="server" value=" " />
Use this to access the hidden field in the aspx page:
$('#tabs a').click(function (e) {
var f = $(this).attr('href');
alert(f);
window.opener.location.href = "RegForm.aspx?" + "val=" + f
$('#hidField', window.parent.document).val(f);
//var c = $('#myIframe').contents().find('#HF1').val();
//alert(c);
//alert($('#myIframe #HF1').val());
//$(' #HF1').val(f);
});
Note that hidField needs to be a dom element in the containing aspx page.
ASPX
<div id="divFrameHolder" style="display: none">
<iframe src="inner/RegSelect.html"name="myIframe" id="myIframe" width="100%" height="200px" frameborder="0" onload="hideLoading()">
</iframe>
<input type="hidden" id="hidField" />
</div>
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;
}
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
}