Hide tab header on ajax:TabContainer - c#

Based upon my condition I only want to remove tabheader from ajax:TabContainer on button click.
My function is:
<script type="text/javascript">
//<![CDATA[
function hideheadertab() {
$('.ajax__tab_header').hide();
}
//]]>
</script>
And in button click I call function like this.
protected void btnAdd_Click(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "tmp", "<script type='text/javascript'>hideheadertab();</script>", true);
}
but no luck.Any trick to do this.Thanks for help.
Note: I want to remove only tab header not whole tab.
tab header html part.
<div id="ctl16_TabContainerManagePortal_header" class="ajax__tab_header">
<span id="ctl16_TabContainerManagePortal_TabPanelPortalAddEdit_tab" class="ajax__tab_active"><span class="ajax__tab_outer"><span class="ajax__tab_inner"><span id="__tab_ctl16_TabContainerManagePortal_TabPanelPortalAddEdit" class="ajax__tab_tab">
<span id="ctl16_TabContainerManagePortal_TabPanelPortalAddEdit_lblAEP">Some Text</span>
</span></span></span></span>
</div>

Related

ASP.NET Webforms Multiple Buttons

I'm making a ASP.NET Web Forms application. I am trying to have a simple way where I can access several controls on the form.
I am trying to access html buttons' serverClick event but it has not been working and only worked on a single button per page.
I first tried to use this code to get the click event when the HTML button was clicked. This is the code for the HTML button.
<form runat="server">
<div class="btn-container">
<a runat="server" onserverclick="infobutton_Click" class="inf-btn" exc-content="inf_button" id="infoButton">Click Here for More Information</a>
</div>
</form>
This code gets the button's click event and displays a sample message box.
Protected Sub infoButton_Click(ByVal sender As Object, ByVal e As EventArgs)
ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "alertMessage", "alert('" & "The Button Was Clicked" & "')", True) 'Displays a JavaScript Alert
End Sub
This code works fine for one button per page, however, I want to use multiple buttons on one page. If I remove the <form> tag, the button click event does not register. If I add a <form> tag for each and every button, it reports an error that there cannot be multiple <form> tags. If I enclose the whole page with a <form> tag, the error reports that the configuration is "corrupted".
This would be straightforward if I had a ASP.NET button control (<asp:button>), but I cannot convert all elements on the page.
I'm not sure what is wrong as all information online says it is correct. Is there any way I can fix this?
<body>
<form id="form1" runat="server">
<div class="btn-container">
<a runat="server" onserverclick="infobutton1_Click" id="infoButton1">
Click Here for More Information</a>
<a runat="server" onserverclick="infobutton2_Click" id="infoButton2">
Click Here for More Information</a>
<a runat="server" onserverclick="infobutton3_Click" id="infoButton3">
Click Here for More Information</a>
</div>
</form>
</body>
Code Behind (C#)
protected void infobutton1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this, Page.GetType(),
"alertMessage", "alert('" + "Button 1 Was Clicked" + "')", true);
}
protected void infobutton2_Click(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this, Page.GetType(),
"alertMessage", "alert('" + "Button 2 Was Clicked" + "')", true);
}
protected void infobutton3_Click(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this, Page.GetType(),
"alertMessage", "alert('" + "Button 3 Was Clicked" + "')", true);
}

Show/Hide href link on click on a button

On a BUTTON click a detail page is generated.
I have a href link when click on it, it navigates in the page.
But on page load there should be only the button (on Clicking it main page is generated) but the href link is also appearing.
I want on the page load there should be only one button by clicking on it href link should appear.
And should disappear when another button is clicked.
Scrip:
$(document).ready(function () {
$('#priorityC').hide();
$('#perC').hide();
});
$('#btnAnalyse').click(function () {
$('#priorityC').show();
$('#perC').show();
});
This is the button:
<asp:ImageButton ID="btnAnalyse" runat="server" OnClick="btnAnalyse_Click"/>
This is the href link which i want to show only on the click of the above button:
Hourly Detailed Priority Representation
<a name="priorityPer">
<div id="perC" class="center">
<asp:Label ID="lblDPTC" runat="server" Text="Detailed Percentage representation of Ticket Count" Visible="false"></asp:Label>
</div>
</a>
Its hiding on page load but not showing on button click.
<asp:ImageButton ID="btnAnalyse" runat="server" ImageUrl="image1.jpg" OnClick="btnAnalyse_Click"/>
Hourly Detailed Priority Representation
<a name="priorityPer">
<div id="per" class="center">
<asp:Label ID="lblDPTC" runat="server" Text="Detailed Percentage representation of Ticket Count" Visible="false"></asp:Label>
</div>
</a>
and on your backend page( codepage.cs)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
linkid.Visible = false;
}
}
protected void btnAnalyse_Click(object sender, ImageClickEventArgs e)
{
if (linkid.Visible == false)
{
linkid.Visible = true;
}
}
protected void btnAnother_Click(object sender, EventArgs e)
{
linkid.Visible = false;
}
You can write your href link inside a div and using Jquery, you can hide and show the the div accordingly.
Code snippet
<script>
// On load hide the div
$(document).ready(function(){
$('#MYDIV').hide();
};
// call this function on button click to show/hide the link
function showHideLink(buttonName)
{
if(buttonName=='blah')
{
$('#MYDIV').hide();
}
else
{
$('#MYDIV').show();
}
}
</script>
Hope this helps.
test.aspx
<li class="nav-item">
<a class="nav-link" id="AdminFaciliy" href="charts.html" runat="server">
<i class="fas fa-fw fa-user">
</i>
text.aspx.cs
if (Utype.Trim().ToUpper()=="ADMIN"){
AdminFaciliy.Visible = true;
}

jQuery(function ($) does not work after partial update in updatepanel

<script type="text/javascript">
//http://digitalbush.com/projects/masked-input-plugin/
jQuery(function ($) {
//phone numbers
alert("test");
var txtInvestContactPhone = $("#<%=txtInvestContactPhone.ClientID%>");
$(txtInvestContactPhone).mask("(999) 999-9999");
});
</script>
i tried adding the pagerequestmanager to the content of the page, but i think i'm doing it wrong:
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add("jQuery(function ($)");
</script>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePageMethods="true">
</asp:ToolkitScriptManager>
i've also tried to registerStartUp Script in my page_load event like so:
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, typeof(Page), Guid.NewGuid().ToString(), "jQuery(function ($);", true);
if (!Page.IsPostBack)
{
but this just breaks my accordion causing the panels to all be unclickable.
i think i'm on the right path here, just need some help with syntax.
jQuery(function ($); isn't a function that can be called, that's like... half a function.
Put your init code in it's own function definition, then call it from your DOM ready handler, and from your startup script.
function init() {
//phone numbers
alert("test");
var txtInvestContactPhone = jQuery("#<%=txtInvestContactPhone.ClientID%>");
jQuery(txtInvestContactPhone).mask("(999) 999-9999");
});
jQuery(function () { init(); });
...
ScriptManager.RegisterStartupScript(this, typeof(Page), Guid.NewGuid().ToString(), "init();", true);

How to call javascript on user control

I have webapplication in c# asp.net 4.0
I have User Control in that I have written javascript :-
<script>
function SetValue() {
alert(document.getElementById('offSetClient').value);
}
</script>
<asp:HiddenField ID="clientDateTime" runat="server" />
<asp:HiddenField ID="offSetClient" runat="server" Value="Test"/>
and this User Control added into a web form.
Please suggest me how can I call this javascript on User Control page load.
You can use Page.ClientScript.RegisterStartupScript to attain this.
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(GetType(), "ShowAlert", "SetValue('" + offSetClient.ClientID + "');", true);
}
Please add an input parameter for the function to get the object of hidden field and pass the same from function.
<script type="text/javascript">
function SetValue(objHdn) {
alert(document.getElementById(objHdn).value);
}
</script>

Button Click using JQuery and C#

I need to know if asp control (Button) is clicked or not using jQuery. This is button coding.
How can I pop up an alert box if someone hit a button using jQuery.
<asp:Button ID="delete_checked_box_button_id" OnClick="deletechecked_box_onclick" runat="server" Text="Delete Checked" />
Thanks in advance.
When you set the ClientIDMode property to Static you can use the Id you set:
$(document).ready(function() {
$('#delete_checked_box_button_id').on('click', function(e) {
alert('Button clicked');
});
}
$('#<%=delete_checked_box_button_id.ClientID %>').click(function() {
alert("Handler for .click() called.");
});
You don't need jQuery, you can use the button's property onClientClick
See this example in MSDN
<script type="text/javascript">
function BuyG2() {
alert('Hai Jquery');
}
</script>//jquery in sourse
protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script type='text/javascript'>BuyG2();</script>", false);
}//ASP Button Click Event

Categories