Here's the ligne :
<%# IIf(Container.DataItem("OldAdress") = Container.DataItem("NewAdress"), "", "Adress")%>
Instead of hard coding "Adress", I want to return a resource variable. Is it possible ?
By using the GetGlobalResourceObject / GetLocalResource object functions. From
https://msdn.microsoft.com/en-us/library/ms227982(v=vs.140).aspx
C#:
<%# Page Language="C#" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Button1.Text =
GetLocalResourceObject("Button1.Text").ToString();
Image1.ImageUrl =
(String)GetGlobalResourceObject(
"WebResourcesGlobal", "LogoUrl");
Image1.Visible = true;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click"
Text="Get Resources" />
<asp:Image ID="Image1" runat="server"
Visible="false" />
</div>
</form>
</body>
</html>
VB.Net:
<%# Page Language="VB" %>
<script runat="server">
Protected Sub Button1_Click( _
ByVal sender As Object, ByVal e As System.EventArgs)
Button1.Text = _
GetLocalResourceObject("Button1.Text").ToString()
Image1.ImageUrl = _
CType(GetGlobalResourceObject("WebResourcesGlobal", _
"LogoUrl"), String)
Image1.Visible = True
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click"
Text="Get Resources" />
<asp:Image ID="Image1" runat="server"
Visible="false" />
</div>
</form>
</body>
</html>
Related
The visible function doesnt work, but why? Is a true set in a callback not allowed?. When I set the visible to true on top of the page(_Default : System.Web.UI.Page) it is working.
information_remedyID.Visible = true;
information_remedyID.Text = inquiryId;
TOP Class:
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>
<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>
Do you use a UpdatePanel with UpdateMode="Conditional"
<asp:UpdatePanel ID="ProfileEditingUpdatePanel" runat="server" UpdateMode="Conditional">
In case you use WPF
information_remedyID.Visibility = Visibility.Visible;
Sorry, overread ASP!
if (inquiryId == null | inquiryId == "")
If this should be an or change it to a double stripe:
if (inquiryId == null || inquiryId == "")
Use a UpdatePanel, like this:
<%# 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>
<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>
And in your code, after you changed the visibility:
MyUpdatePanel.Update();
I couldn't get this to work either.
A workaround is to use Style="display: none;" instead of Visible="False". Then you can reveal it with
information_remedyID.Style["display"] = "initial";
I have one site master page and one content page. Whenever I click button in content page it is not triggering click event method to execute.
SiteMaster Code:
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
</head>
<body background="../../Content/city-balcony#2x.jpg">
<form id="form1" runat="server">
<div class="page">
<div id="header">
<div id="title">
<h1>Welcome to E-Meeting</h1>
</div>
<div id="logindisplay">
<% Html.RenderPartial("LogOnUserControl"); %>
</div>
<div id="menucontainer">
<ul id="menu">
<li><%: Html.ActionLink("Home", "Index", "Home")%></li>
<%
if (Request.IsAuthenticated)
{
%>
<li><%: Html.ActionLink("Chat", "ViewPage1")%></li>
<% }
%>
<li><%: Html.ActionLink("About", "About", "Home")%></li>
</ul>
</div>
</div>
<div id="main">
<%="Last communicated at : " + DateTime.Now.ToLongTimeString()%>
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<div id="footer">
</div>
</div>
<br />
<br />
</div>
</form>
</body>
</html>
Content Page:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Modified by click event";
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
ChT
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>ChT</h2>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="On Load"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Whenever I click button I want label text to be "Modified by click event" but it remains same "On Load". Can someone please help
Try adding a trigger in your update panel as shown:
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
And Check ScriptManager's EnablePartialRendering and remove it if it presented or set it to true
you can add a method using C# to trigger the event.
double-click button to create a button click event.
add a code to change the label text to "Modified by click event"
for example,
protected void Button1_Click(object sender, EventArgs e){
Label1.text = "Modified by click event";
}
by the way, you could get rid of Text="On Load" in your aspx code. (your code would be: <asp:Label ID="Label1" runat="server"></asp:Label>, then add a page_load method in your .cs file:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Label1.text = "On load";
}
in this case, it will display "on load" when you open the webpage, and it will display "Modified by click event" when you clicked button.
hope it
I've got MasterPage and Content Page. On the ContentPage there is some label and i want to change it's text when clicked on button on the content page without refreshing the page.
Default.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>
<script runat="server">
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Label SensorTemperatureLabel = (Label)this.Master.FindControl("SensorTemperatureLabel");
if (SensorTemperatureLabel != null)
{
SensorTemperatureLabel.Text = "TEST";
}
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" />
</asp:Content>
MasterPage.master
Part of the code with label
<div class="sidebar">
<!-- insert your sidebar items here -->
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="SensorTemperatureLabel" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
I have prepared you complete solution to show you how you can do this.
First sample master. Take notice I have added ScriptManager to page and target label is inside content template:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebTester.Site1" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="SensorTemperatureLabel" runat="server" Text="TEMP"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Now here is content page, button is also placed inside content template:
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebTester.WebForm1" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Test" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
And finally here is the code, I get refrence to label by using FindControl:
protected void Button1_Click(object sender, EventArgs e)
{
Site1 site = this.Master as Site1;
if (site != null)
{
Label SensorTemperatureLabel = site.FindControl("SensorTemperatureLabel") as Label;
SensorTemperatureLabel.Text = DateTime.Now.ToString();
}
}
This code will update label on master page without complete page postback.
If the label is not in <ContentTemplate />, you can access with javascript
var SensorTemperatureLabel = document.getElementById("<%=SensorTemperatureLabel%>");
SensorTemperatureLabel.innerHTML = "newValue";
Otherwise, the ID is generated and you'll need
var SensorTemperatureLabel = document.getElementById("<%= this.Master.FindControl("SensorTemperatureLabel").ClientID %>");
I hope my answer help in this case
if you have Label in master page named " Label1" then
you can change value there like this
VB
Dim lb as label= me.master.findcontrol("Label1"):lb.text="Hello worold"
Peace upon you all.
i use from ajax tabcontainer .and i want to when value of hiddenfield is not 1(value of hiddenfield change when i click in gridview,i dont have problem with set value for hiddenfield) and user click in email tab it alerts and stays in first tab.but in my code it alert and changes tab.i want to stay in cuurent tab.
i write this code but it dosent work.
please help me.
<%# Page Language="C#" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
<script type="text/javascript">
function SetActiveTab() {
var hfd = $get('<%=HiddenField1.ClientID%>');
if (hfd.value != "1") {
alert("hitttttttt");
var ctrl = $find('TabContainer1');
ctrl.set_activeTab(ctrl.get_tabs()[0]);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Ajax Control - Tabs </title>
</head>
<body>
<form id="form1" runat="server">
<b>Tabs Demonstration</b> <br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:HiddenField ID="HiddenField1" runat="server" />
<br />
<asp:TabContainer runat="server" ID="TabContainer1" Height="138px" ActiveTabIndex="0"
Width="402px">
<asp:TabPanel runat="server" ID="Panel1" HeaderText="Address" >
<ContentTemplate>
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<table>
<tr><td>First Name:</td><td><asp:TextBox ID="txtName" runat="server" /></td></tr>
<tr><td>Address:</td><td><asp:TextBox ID="txtAddress" runat="server" /></td></tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel runat="server" ID="Panel3" HeaderText="Email" OnClientClick="SetActiveTab" >
<ContentTemplate>
Email: <asp:TextBox ID="txtEmail" runat="server" />
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel runat="server" ID="Panel2" HeaderText="Login Details" >
<ContentTemplate>
<table>
<tr> <td>User Name:</td><td><asp:TextBox ID="txtUser" runat="server" /></td></tr>
<tr> <td>Password:</td><td><asp:TextBox ID="txtPass" runat="server" /></td></tr>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
</form>
The one solution I found is to remove OnClientClick handler and use the javascript below:
function pageLoad() {
var tabContainer = $find('<%= TabContainer1.ClientID %>');
var hfd = $get('<%= HiddenField1.ClientID %>');
var oldSetActiveTab = Function.createDelegate(tabContainer, tabContainer.set_activeTab);
tabContainer.set_activeTab = function (value) {
if (value.get_id() == '<%= Panel3.ClientID %>' && hfd.value != "-1") {
alert("oops");
}
else {
oldSetActiveTab(value);
}
};
}
I have listview and every row has a Drop Down List and a hyperlink control.
What i'm trying to do is change the navigate url for the hyperlink based on the selection of the drop down list. How would I get the row that the control posted back from so I can find the hyperlink control?
You may try the following:
<%# Page Language="C#" %>
<script type="text/C#" runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MyList.DataSource = Enumerable.Range(1, 5);
MyList.DataBind();
}
}
protected void DDLChange(object sender, EventArgs e)
{
var ddl = (DropDownList)sender;
var link = (HyperLink)ddl.Parent.FindControl("MyLink");
link.NavigateUrl = ddl.SelectedValue;
link.Text = ddl.SelectedValue;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="Form1" runat="server">
<asp:ListView ID="MyList" runat="server">
<ItemTemplate>
<div>
<asp:DropDownList runat="server" AutoPostBack="true" OnSelectedIndexChanged="DDLChange">
<asp:ListItem Value="http://www.google.com" Text="http://www.google.com" />
<asp:ListItem Value="http://www.bing.com" Text="http://www.bing.com" />
<asp:ListItem Value="http://www.yahoo.com" Text="http://www.yahoo.com" />
</asp:DropDownList>
<asp:HyperLink runat="server" ID="MyLink" NavigateUrl="http://www.google.com" Text="http://www.google.com" />
</div>
</ItemTemplate>
</asp:ListView>
</form>
</body>
</html>