Asp.net - Can't Change Visibility of Panel After Downloading File - c#

I am displaying a panel that containg a button. When the user clicks the button, it does some processing and then downloads a file for the user. The code for that is shown here:
private void OpenForm(string content, string formName)
{
Byte[] bytes = System.Text.Encoding.Default.GetBytes(content);
this.Response.AppendHeader("Content-Type", "application/msword");
this.Response.AppendHeader("Content-Length", bytes.Length.ToString());
this.Response.AppendHeader("Content-disposition", "attachment; filename=" + formName);
this.Response.BinaryWrite(bytes);
ReturnToMemberScreen();
this.Response.Flush();
this.Context.ApplicationInstance.CompleteRequest();
}
In the function ReturnToMemberScreen, I am changing the visibility of some panels. Here is the function:
private void ReturnToMemberScreen()
{
this.panelMappings.Visible = false;
this.MemberEditPNL.Visible = true;
}
I can download the file perfectly fine, my issue is that the visibility of my panels don't change. Does it have something to do with writing to the Response like I am?

Do not use Visible = false as that causes the element to not be rendered. Try:
// To hide:
Panel1.Style.Add("display", "none");
// To show:
Panel1.Style.Add("display", "block");

Do you set the visibility of the panels in the Page_Load event? If so, and if you're not handling postbacks within the event, then the visibility settings might be overriding the settings in ReturnToMemberScreen.

Looking closer, I think I cannot make any changes to the page because I am changing the Content-Type of the response from "text/html" to application/msword when I do this:
this.Response.AppendHeader("Content-Type", "application/msword");
As I result, I am making all my changes with CSS and Javascript instead. By default, I set my panels to either show or hide using css:
.hide
{
display:none;
}
.show
{
display:block;
}
Then I set the OnClientClick of the button to the following Javascript function to change the display:
function visible()
{
document.getElementById('<%=panelForms.ClientID %>').style.display = 'none';
document.getElementById('<%=MemberEditPNL.ClientID %>').style.display = 'block';
}

Related

How to dispay and hide div in angularjs

I am having a loader in my screen which will be displayed on the screen until page gets loaded or page gives any error.
I am having a div where I have the loader...
<div id:loader class="loading">
...and I am trying to show and hide based on the page load status.
How can I hide and show the loader? Here in my js code:
oninit() {
$scope.loader.showDiv = true;
function(success) {
$scope.loader.showDiv= false;
}
}
But it is not working. Now it is running continuously on the page. Any helping hand on achieving the same.
Use ng-show Try this
<div id:loader class="loading" ng-show="showDiv">
Still use your init function to set showDiv = true or false
Or set a scope for loading in your init
$scope.isLoading = true;
Put this in your div
ng-show="!isLoading"
Set it to false when page is loaded
$scope.isLoading = false;

How to make ImageButton not clickable

I have a number of ImageButtons within a repeater, depending on each record some of these images will be clickable and others, I have disabled the button to stop postback.
I have now changed the opacity of each image so that unless you are hovering on that imagebutton it will be 0.6. The trouble is, for those that I have disabled, obviously I cannot alter the opacity on/off hover.
Currently I am doing this:
if (vessel.IsRegistered)
{
imagebuttonRegistration.ImageUrl = ("../Images/Icons/registrationApproved.gif");
imagebuttonRegistration.CommandArgument = null;
DisableImageButton(imagebuttonRegistration);
imagebuttonRegistration.ToolTip = GetLocalResourceObject("imageButRegistrationRegisteredText").ToString();
}
public static void DisableImageButton(ImageButton imagebutton)
{
imagebutton.Attributes.Remove("href");
imagebutton.Attributes.Add("disabled","disabled");
}
But as disabling the button is now causing me problems, how might I just stop the button being clickable/no postback but allow the other attributes to be used.
Different way using Css:
In your css file add:
.notclickable{
cursor:text;
}
And in DisableImageButton method add:
imagebutton.Attributes["class"] ="notclickable";
try this:
imagebutton.Attributes.Add("onclick","return false");
imagebutton.Style.Add("cursor","context-menu");
you can use CSS
.imagebutton:disabled {
opacity:0.7;
}
check this out:
http://www.w3schools.com/cssref/sel_disabled.asp

User text input handling using TextBox

I have this control:
I'm trying to create a kind of validation, that whenever the user enters text to the TextBox, the "Add" button will be Enabled, and when the text is "" (null), the "Add" button is disabled.
I dont want to use validators.
here's the code:
protected void addNewCategoryTB_TextChanged(object sender, EventArgs e)
{
if (addNewCategoryTB.Text != "")
addNewCategoryBtn.Enabled = true;
else
addNewCategoryBtn.Enabled = false;
}
The problam is, that when the user enter's text, the "Add" button doesn't changes from disabled to enabled (and vice versa)...
any ideas?
Is it Web Forms? In Web Forms the TextChanged event of the TextBox won't fire by default.
In order to fire the event, you have to set the AutoPostBack property of the TextBox to true.
BUT, this would perform a HTTP post, what is kink of ugly, or you can wrap that in an UpdatePanel
A more elegant option, is to do that using jQuery, to do that in jQuery, you'll need some code like:
$(document).ready(function() {
$("#<%= yourTextBox.ClientID %>").change(function() {
var yourButton = $("#<%= yourButton.ClientID %>")
yourButton.attr('disabled','disabled');
yourButton.keyup(function() {
if($(this).val() != '') {
yourButton.removeAttr('disabled');
}
});
});
});
You'll need to accomplish this with Javascript, since ASP.NET is incapable of performing such client-side modifications. Think about it ... every time you pressed a letter inside the text box, it would have to postback and refresh the page in order to determine if the text box was empty or not. This is one way that ASP.NET differs from Winforms/WPF.
TextChanged events will make postback on server every time. You don't need to increase those request for such task.
You can use jquery to achieve this
var myButton = $("#btnSubmit");
var myInput=$("#name");
myButton.prop("disabled", "disabled");
myInput.change(function () {
if(myInput.val().length > 0) {
myButton.prop("disabled", "");
} else {
myButton.prop("disabled", "disabled");
}
});
JS Fiddle Demo
You just need to take care of elements Id when you are using Server Controls. For that Either you can use ClientID or set property ClientIdMode="Static"

Change page state with JavaScript, old state gets recalled on postback

Basically we have the "illusion" of an notification message box that exists as .Visible = false in the MasterPage. When it comes time to display a message in the box, we run a method that looks like this:
public static void DisplayNotificationMessage(MasterPage master, string message)
{
if (Master.FindControl("divmsgpanel") != null)
{
master.FindControl("divmsgpanel").Visible = true;
}
if (master.FindControl("divdimmer") != null)
{
master.FindControl("divdimmer").Visible = true;
}
TextBox thetxtbox = (TextBox)master.FindControl("txtboxmsgcontents");
if (thetxtbox != null)
{
thetxtbox.Text = message;
}
}
Basically through our designers awesome CSS voodoo, we end up with what appears to be a floating message box as the rest of the page appears dimmed out. This message box has a "Close" button to dismiss the "popup" and restore the dimmer, returning the site to the "normal" visual state. We accomplish this with JavaScript in the MasterPage:
function HideMessage() {
document.getElementById("<%# divmsgpanel.ClientID %>").style.display = 'none';
document.getElementById("<%# divdimmer.ClientID %>").style.display = 'none';
return false;
}
and the button's declaration in the .aspx page calls this HideMessage() function OnClientClick:
<asp:Button ID="btnmsgcloser" runat="server" Text="Close" style="margin: 5px;"
OnClientClick="return HideMessage()" />
The problem:
All future postbacks cause the MasterPage to "remember" the state of those divs from how they were before the HideMessage() JavaScript was executed. So in other words, every single postback after the initial call of the DisplayNotificationMessage() method causes the page to return to divmsgpanel.Visible = true and divdimmer.Visible = true, creating an endlessly annoying message box that incorrectly pops up on every postback.
The question:
Since we want the Close function to stay client-side JavaScript, how can we "notify" the page to stop reverting to the old state on postback, for just these two divs?
Can you try setting them to Visible = false in Master_Page Load event? It should hide them and reshow them just when you call DisplayNotificationMessage

Javascript does not take hidden text box value?

I am using this javascript function to show different popups if location count varies. Here the txthiddenloccount value is null if the txtbox's visibility is false. If the visibility is true, it works fine. What strange is this??? Can someone help me out.
function isPageValid()
{
var validated = Page_ClientValidate('groupProfile');
var loccount = document.getElementById("ctl00_ContentPlaceHolder1_txthiddenloccount").value;
if(validated)
{
if(loccount == '1')
{
var mdlPopup = $find('<%= ModalPopupExtendersavechanges.ClientID %>');
if(mdlPopup)
{
mdlPopup.show();
}
}
else
{
var mdlPopup = $find('<%= ModalPopupExtenderMerchantUpdate.ClientID %>');
if(mdlPopup)
{
mdlPopup.show();
}
}
}
}
if txthiddenloccount is an asp:TextBox that has the Visible property set to false then it does not exist on the page that is readable by javascript. It will be stored in the ViewState.
For something like this you're probably better off using an asp:HiddenField and setting the value, that will create an input type='hidden' that will be accessible through javascript.
Here you are trying to get txthiddenloccount control's value which hasn't rendered on the page because its visibility is false.
so first you have to check if it is null i.e you can write code like this.
var loccount='';
if(document.getElementById("ctl00_ContentPlaceHolder1_txthiddenloccount") != null)
{
loccount = document.getElementById("ctl00_ContentPlaceHolder1_txthiddenloccount").value;
}
If the Visible property of the control is set as false via ASP.NET, it will be part of the control tree but will never actually get rendered to the page. If it doesn't get rendered to the page, JavaScript can't access it.
If you want to hide it using ASP.NET, you could do it this way in C#...
txthiddenloccount.Style.Add("display", "none");
That will not prevent the control from rendering on the page AND it will use CSS to hide it. Alternatively, you could do this, but it might not be what you want, visually...
txthiddenloccount.Style.Add("visibility", "hidden");
Hope that helps.

Categories

Resources