2013-02-28 3 views
0

La fonction visible ne fonctionne pas, mais pourquoi? Est-ce qu'un vrai jeu dans un rappel n'est pas autorisé? Lorsque je mets le visible à true en haut de la page (_Default : System.Web.UI.Page) cela fonctionne.label.visible = true ne fonctionne pas

information_remedyID.Visible = true; 
information_remedyID.Text = inquiryId; 

TOP Classe:

public partial class _Default : System.Web.UI.Page 
{ 
....... 
    private static string inquiryId;  

...... 

private void InsertIncidentCallback(server3.ILTISAPI api, IAsyncResult result, string username, string msg_id) 
     { 
      string message; 
      api.EndInsertIncident(result, out message); 

      if (message == null) 
      { 
       string responseXML; 
       api.REMEDY_ReadResponseXML(username, out responseXML, out msg_id); 
       XDocument doc = XDocument.Parse(responseXML); 
       inquiryId = (string)doc.Root.Element("inquiry_id"); 

       if (inquiryId == null | inquiryId == "") 
       { 
        information_text.Text = "...."; 
       } 
       else 
       { 
        information_remedyID.Visible = true; 
        information_remedyID.Text = inquiryId; 
        //create_LanDesk(computer_idn, swidn_choice, swName_choice, inquiryId); 
       } 
      } 
      else 
      { 
       information_text.Visible = true; 
       information_text.Text = "..."; 
      } 
     } 
} 

asp:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head id="Head1" runat="server"> 
    <title>Willkommen im BISS</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <span style="font-size: 16pt"><strong>BISS<br /> 
     </strong><span style="font-size: 12pt"> 
      <br /> 
      Angemeldet als: 
      <asp:Label ID="user_id" runat="server" Text="user_id"></asp:Label><br /> 
      Hostname: 
      <asp:Label ID="hostname_id" runat="server" Text="hostname_id"></asp:Label> 
      <br /> 
      CI Nummer: 
      <asp:Label ID="CI_NR" runat="server" Text="CI_NR"></asp:Label></span></span> 
     <br /> 
     <br /> 
     <asp:DropDownList ID="softwarelist" runat="server" DataTextField="SoftwareName" DataValueField="SoftwareName"> 
     <asp:ListItem Text="Bitte Software auswählen" Value=""></asp:ListItem> 
     </asp:DropDownList>&nbsp; 
      <asp:Button ID="requestbt" runat="server" OnClick="Button1_Click" Text="Software zuweisen" /><br /> 

      <asp:Label ID="information_text" runat="server" Text="information_text" Visible="False"></asp:Label><br /> 
     <asp:Label ID="information_remedyID" runat="server" Text="information_remedyID" Visible="False"></asp:Label> 
     <br /> 
    </form> 
</body> 
</html> 
+2

N'utilisez jamais de champs statiques dans ASP.NET si vous ne voulez pas que tous les utilisateurs partagent la même valeur. Prenez l'habitude d'utiliser des variables locales à la place. –

+0

qui peut être à cause de rappel sera appelé après que la page est rendue dans le navigateur – TalentTuner

+0

le rappel est utilisé, lorsqu'un utilisateur clique sur un bouton. – mnlfischer

Répondre

1

Utilisez-vous un UpdatePanel avec UpdateMode = "conditionnelle"

<asp:UpdatePanel ID="ProfileEditingUpdatePanel" runat="server" UpdateMode="Conditional"> 

Si vous utilisez WPF

information_remedyID.Visibility = Visibility.Visible; 
  • Désolé, overread ASP!
+0

non, je ne sais pas. Toutes les autres étiquettes fonctionnent très bien. – mnlfischer

+0

Alors vous cachez/montrez d'autres étiquettes aussi, et cela fonctionne? –

+0

Le bouton d'où vous appelez ce code est à l'intérieur du panneau de mise à jour ou non .. – Rahul

0
if (inquiryId == null | inquiryId == "") 

Si cela devrait être une ou changer à une double bande:

if (inquiryId == null || inquiryId == "") 
+0

devrait être un ou. – mnlfischer

+0

Donc, c'est juste une faute de frappe dans le poste? – MrFox

+0

est | le mauvais oparateur pour ou? – mnlfischer

0

Utilisez un UpdatePanel, comme ceci:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>Willkommen</title> 
</head> 
<body> 

<form id="form1" runat="server"> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
     </asp:ScriptManager>  
    <asp:UpdatePanel ID="MyUpdatePanel" runat="server" UpdateMode="Conditional"> 
     <ContentTemplate> 
      <span style="font-size: 16pt"> 
      <strong> 
       BISS<br /> 
      </strong> 
      <span style="font-size: 12pt"> 
       <br /> 
       Angemeldet als: 
       <asp:Label ID="user_id" runat="server" Text="user_id"></asp:Label><br /> 
       Hostname: 
       <asp:Label ID="hostname_id" runat="server" Text="hostname_id"></asp:Label> 
       <br /> 
       CI Nummer: 
       <asp:Label ID="CI_NR" runat="server" Text="CI_NR"></asp:Label></span></span> 
      <br /> 
      <br /> 
      <asp:DropDownList ID="softwarelist" runat="server" DataTextField="SoftwareName" DataValueField="SoftwareName"> 
       <asp:ListItem Text="Bitte Software auswählen" Value=""></asp:ListItem> 
      </asp:DropDownList>&nbsp; 
       <asp:Button ID="requestbt" runat="server" OnClick="Button1_Click" Text="Software zuweisen" /><br /> 

      <asp:Label ID="information_text" runat="server" Text="information_text" Visible="False"></asp:Label><br /> 
      <asp:Label ID="information_remedyID" runat="server" Text="information_remedyID" Visible="False"></asp:Label> 
      <br /> 
     </ContentTemplate> 
    </asp:UpdatePanel> 
</form> 

</body> 
</html> 

Et dans votre code, après avoir a changé la visibilité de:

MyUpdatePanel.Update(); 
+0

est-ce la seule option? J'ai reçu une erreur "Serveur inconnu: UpdatePanel" – mnlfischer

+0

Vous auriez besoin d'un ScriptManager pour le gérer aussi Vous pourriez aller à travers le tutoriel: http://msdn.microsoft.com/de-de/library/bb398864%28v = vs.100% 29.aspx –

+0

Et oui, vous avez besoin d'un UpdatePanel!Le html est statique, et le navigateur ne sait pas, si vous changez quelque chose sur votre serveur, donc vous devez dire au navigateur qu'il y a eu des changements et le forcer à recharger, un navigateur ne change pas d'observateur tout seul! –

0

Je ne pouvais pas faire fonctionner cela non plus. Une solution de contournement consiste à utiliser Style="display: none;" au lieu de Visible="False". Ensuite, vous pouvez le révéler avec information_remedyID.Style["display"] = "initial";

Questions connexes