label.visible = true not working - c#

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";

Related

How to get web user control's text box value using javascript

I am developing an calendar user control using Ajax calendar extender.
User control code
<%# Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" ClientIDMode="Predictable" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxControl" %>
<link rel="stylesheet" href="GridViewCSSThemes/YahooGridView.css" type="text/css" media="screen" />
<div style="position:relative;border:none;">
<asp:TextBox ID="txtDate" MaxLength="10" ToolTip="DD/MM/YYYY" Width="100"
CssClass="tb10" runat="server">
</asp:TextBox>
<asp:ImageButton ImageUrl="~/GridViewCSSThemes/Images/Calendar_scheduleHS.png" ID="imgCalender" runat="Server"
BorderWidth="0" ImageAlign="absmiddle" />
<ajaxControl:CalendarExtender ID="AjaxCalenderCtrl" runat="server" Format="dd/MM/yyyy" PopupPosition ="TopLeft"
TargetControlID="txtDate" CssClass="red" FirstDayOfWeek="Sunday" PopupButtonID="imgCalender">
</ajaxControl:CalendarExtender>
<ajaxControl:TextBoxWatermarkExtender WatermarkCssClass="tb10" ID="txtWaterMarkDate"
runat="server" WatermarkText="DD/MM/YYYY" TargetControlID="txtDate">
</ajaxControl:TextBoxWatermarkExtender>
<ajaxToolkit:MaskedEditExtender ID="MaskedEdit_dt" runat="server"
TargetControlID="txtDate"
Mask="99/99/9999"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Date"
AcceptAMPM="true"
AcceptNegative="Left"
ErrorTooltipEnabled="True" />
<ajaxToolkit:MaskedEditValidator ID="MaskedEditV_dt" runat="server"
ControlExtender="MaskedEdit_dt"
ControlToValidate="txtDate"
EmptyValueMessage="Date is required"
InvalidValueMessage="Date is invalid"
Display="Dynamic"
TooltipMessage="Input a date"
EmptyValueBlurredText="Date is required"
InvalidValueBlurredMessage="Date is invalid"
IsValidEmpty="false"
ValidationGroup="MKE" />
<%--<asp:RegularExpressionValidator ID="regexpvalEndDateEdit" ErrorMessage="!" ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d"
ControlToValidate="txtDate" runat="server"></asp:RegularExpressionValidator>--%>
</div>
Code behind user control
internal string _DValue;
public string DValue
{
get
{
if (_DValue == "")
{
_DValue = txtDate.Text;
}
else
{
txtDate.Text = _DValue;
}
return _DValue;
}
set { _DValue = value; }
}
public string IdClientId
{
get { return this.ClientID; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
I am able to get controls value using server side code.
Now i need to access text-box(txtDate) value and MaskedEditValidator(MaskedEditV_dt) inerHtml from javascript.
How can i do this.
Edit-1
User control in aspx page
<%# Page Language="C#" AutoEventWireup="true" CodeFile="CustomControlTest2.aspx.cs" Inherits="CustomControlTest2" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxControl" %>
<%# Register TagPrefix="uc1" TagName="UCCalender" Src="~/WebUserControl.ascx" %>
<!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>User Control Test</title>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager runat="server" ID="ScriptManager1" EnablePageMethods="true" />
<div>
<table>
<tr>
<td>
<uc1:UCCalender ID="UCCalStartDate" runat="server" DValue="" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnExe" runat="server" Text="Submit" onclick="btnExe_Click" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblMsg" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
Code behind
protected void btnExe_Click(object sender, EventArgs e)
{
lblMsg.Text = UCCalStartDate.DValue;
}
ASP.NET loads to display the UserControl, it ONLY renders the contents of the UserControl. The Controls in the usercontrol will rendered with the ID as $content_UControlName_Control. You can check this after the rendering the page. You can access the contol using that ID from Javascript like document.getElementById(content_UControlName_Control).
Finally i got answer. Thanks to Nag
On button click
<asp:Button ID="btnExe" runat="server" Text="Submit" OnClientClick="getValue('UCCalStartDate_txtDate','UCCalStartDate_MaskedEditV_dt');" onclick="btnExe_Click" />
Javascript
function getValue(id,msk) {
alert(document.getElementById(id).value);
alert(document.getElementById(msk).innerHTML);
}
Finaly i am able to access calander control's text-box value using java-script

call javascript from c#

I know this question is asked before, and I looked it up, and found this sulotion:
Page.ClientScript.RegisterStartupScript(this.GetType(), "click", "test();", true);
so I put that in my c# method, and the following javascript code in my head.
<script type ="text/javascript">
function test() {
alert("succes");
}
</script>
this is my html where i call the code behind method.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div id="ampwirecalc">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:DropDownList ID="dropdownsize" OnSelectedIndexChanged="wirecalc" onchange="runscalc()" AutoPostBack="true" runat="server">
<asp:ListItem Text="Select Wire Size" value="-1"/>
<asp:ListItem Text="1/0 gauge" Value="0" />
<asp:ListItem Text="4 gauge" Value="1" />
<asp:ListItem Text="8 gauge" Value="2" />
</asp:DropDownList>
<script type="text/javascript">
function runscalc()
{
var totalRMS = document.getElementById('<%=tbx_anw3.ClientID%>').value;
document.getElementById('<%=HiddenField1.ClientID%>').value = totalRMS;
}
</script>
<!--These are the texts giving information on the options-->
<div class="textwirecalc">
<p class="selectedwire">Selected Wire:</p>
<p class="neededruns">Needed Runs:</p>
<p class="selectedsize">Selected size:</p>
</div>
<!--These are the labels that wil show the calculated info-->
<div class="labelwirecalc">
<asp:Label ID="wiretype" runat="server" Text="Wire type will show here"></asp:Label>
<asp:Label ID="wireruns" runat="server" Text="Needed runs will show here"></asp:Label>
<asp:Label ID="wiresize" runat="server" Text="Wire size will show here"></asp:Label>
</div>
</ContentTemplate>
</asp:UpdatePanel>
does anyone know what I'm doing wrong, and what I should do instead.
thanks in advance.
Try this
Page.ClientScript.RegisterStartupScript(this.GetType(), "click", "test();", false);
Reference
last parameter true/false indicate- whether to add script tags.
you can give the javascript like below, no need to write javascript function
Page.ClientScript.RegisterStartupScript(this.GetType(), "click","alert('succes');", true);
UPDATE
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(),
"click", "alert('succes');", true);
The third parameter must be enclosed with script tags as the
http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx says.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!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>
<script type="text/javascript">
function test() {
alert("succes");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div id="ampwirecalc">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:DropDownList ID="dropdownsize" onchange="runscalc()" AutoPostBack="true" runat="server" OnSelectedIndexChanged="dropdownsize_SelectedIndexChanged">
<asp:ListItem Text="Select Wire Size" Value="-1" />
<asp:ListItem Text="1/0 gauge" Value="0" />
<asp:ListItem Text="4 gauge" Value="1" />
<asp:ListItem Text="8 gauge" Value="2" />
</asp:DropDownList>
<script type="text/javascript">
</script>
<!--These are the texts giving information on the options-->
<div class="textwirecalc">
<p class="selectedwire">
Selected Wire:</p>
<p class="neededruns">
Needed Runs:</p>
<p class="selectedsize">
Selected size:</p>
</div>
<!--These are the labels that wil show the calculated info-->
<div class="labelwirecalc">
<asp:Label ID="wiretype" runat="server" Text="Wire type will show here"></asp:Label>
<asp:Label ID="wireruns" runat="server" Text="Needed runs will show here"></asp:Label>
<asp:Label ID="wiresize" runat="server" Text="Wire size will show here"></asp:Label>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
And code behind,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Page.ClientScript.RegisterStartupScript(this.GetType(), "click", "test();", true);
}
protected void dropdownsize_SelectedIndexChanged(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(),
"click", "test();", true);
}
}
}
Try this code.

Page_Load executing Twice

I know that this question has been asked before, but none of the remedies seem to be my solution.
I have an aspx page and a code behind with a Page_Load routine. My routine writes a record to a SQL table to capture the user's credentials.
The Page_Load has a !IsPostBack check, aspx has AutoEventWireup="True", and I have no img or any other element that would cause an AutoPostback to my knowledge. Still Page_Load is called twice.
Here is my .aspx page and the code behind. I am hoping someone can help.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="feedback.aspx.cs" Inherits="MEAU.Web.Components.SupportCenter.feedback" %>
<%# Import Namespace="Sitecore.Configuration" %>
<%# Import Namespace="Sitecore.Security.Accounts" %>
<%# Import Namespace="System.Data" %>
<%# Import Namespace="System.Data.SqlClient" %>
<!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">
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.easing.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.accordion.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.pngFix.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/global.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery-tmpl.js"></script>
<head id="Head1" runat="server">
<style>
p.titlefont
{
font-family: "Arial" , Helvetica, Sans-Serif;
font-size:"12px";
}
</style>
<title>Feedback</title>
<script type="text/javascript">
function Init() {
var obj = window.dialogArguments;
var url = document.getElementById("url1");
var login = document.getElementById("login");
}
function getRadioValue(theRadioGroup) {
for (var i = 0; i < document.getElementsByName(theRadioGroup).length; i++) {
if (document.getElementsByName(theRadioGroup)[i].checked) {
return document.getElementsByName(theRadioGroup)[i].id;
}
}
}
function WriteToFile(sText) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fo = fso.OpenTextFile('c:\\\inetput\\wwwwroot\LogFile.txt', 8, true, 0); // 8=append, true=create if not exist, 0 = ASCII
fo.WriteLine();
fo.Write(sText);
fo.Close();
}
</script>
</head>
<!--<body onload="javascript:Init();"> -->
<body>
<form id="form1" runat="server">
<div>
<p class="titlefont">
<asp:Literal ID="quest" Text="Did this resolve your issue?" runat="server" />
<br />
<br />
<asp:CheckBox ID="yes" runat="server" Text="Yes" Checked="true"
Font-Names="Arial" Font-Size="12px" /><br />
<asp:CheckBox ID="no" runat="server" Text="No" Font-Names="Arial"
Font-Size="12px" /><br />
<asp:Literal ID="lit" Text="Please select at least one answer" runat="server" Visible="false"/><br />
<asp:CheckBox ID="scall" runat="server" Text="Did this prevent a Service Call?" Visible="false" Font-Names="Arial"
Font-Size="12px" /><br />
<asp:CheckBox ID="parts" runat="server" Text="Did this prevent a Parts Shipment?" Visible="false"
Font-Names="Arial" Font-Size="12px" /><br />
<asp:CheckBox ID="wrnt" runat="server" Text="Is this under Warranty?" Font-Names="Arial" Visible="false"
Font-Size="12px" /><br />
<asp:CheckBox ID="none" runat="server" Text="None of the above" Font-Names="Arial" Visible="false"
Font-Size="12px" /><br />
<br />
<asp:Button ID="run" Text="SUBMIT" OnClick="Run_Write" runat="server" Font-Names="Arial"
Font-Size="12px" /><br />
<asp:Button ID="cancel" Text=" CANCEL " OnClick="Cancel_btn" runat="server" Font-Names="Arial"
Font-Size="12px" />
</p>
</div>
</form>
</body>
</html>
my code Behind:
protected void Page_Load(object sender, EventArgs e)
{
login = Sitecore.Security.Accounts.User.Current.Profile.Email;
myurl = Request.QueryString["value"];
if (!IsPostBack)
{
// Write a record and capture the User's credententials, even if they do not take an action
SqlConnection conn = new SqlConnection(Sitecore.Configuration.Settings.GetConnectionString("feedback"));
SqlCommand cmd = new SqlCommand("Insert_fb", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#login", login);
cmd.Parameters.AddWithValue("#url", myurl);
cmd.Parameters.AddWithValue("#response", "No");
cmd.Parameters.AddWithValue("#noResponse", "Yes");
cmd.Parameters.AddWithValue("#date", DateTime.Now);
cmd.Parameters.AddWithValue("#serviceCall", "No");
cmd.Parameters.AddWithValue("#partsShipment", "No");
cmd.Parameters.AddWithValue("#warranty", "No");
cmd.Parameters.AddWithValue("#cancel", "No");
cmd.Parameters.AddWithValue("#none", "No");
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception("Error on file update" + ex.Message);
}
finally
{
conn.Close();
}
}
}

The name 'grdUserActivity' does not exist in the current context

I have a grid that is named grdUserActivity. I'm not sure what the error means.
The name 'grdUserActivity' does not exist in the current context
C#
public partial class frmViewPersonnel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Declares the DataSet
dsUserActivity myDataSet = new dsUserActivity();
// Fill the dataset with what is returned from the function
myDataSet = clsDataLayer.GetUserActivity(Server.MapPath("PayrollSystem_DB.mdb"));
// Sets the DataGrid to the DataSource based on the table
grdUserActivity.DataSource = myDataSet.Tables["tblUserActivity"];
// Binds the DataGrid
grdUserActivity.DataBind();
}
}
}
.ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeFile="frmPersonnel.aspx.cs" Inherits="frmPersonnel" %>
<!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">
<div align="center">
</div>
<asp:Panel ID="Panel1" runat="server" Height="250px" HorizontalAlign="Left"
Width="300px">
<asp:Label ID="Label1" runat="server" Text="First Name:" Width="80px"></asp:Label>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Last Name:" Width="80px"></asp:Label>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="Pay Rate:" Width="80px"></asp:Label>
<asp:TextBox ID="txtPayRate" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label4" runat="server" Text="Start Date:" Width="80px"></asp:Label>
<asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label5" runat="server" Text="End Date:" Width="80px"></asp:Label>
<asp:TextBox ID="txtEndDate" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnSubmit" runat="server"
PostBackUrl="~/frmPersonnalVerified.aspx" Text="Submit"
onclick="btnSubmit_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
<br />
<asp:Label ID="lblError" runat="server"></asp:Label>
</asp:Panel>
</form>
Not sure if this is a type-o
But your aspx file is pointing to frmUserActivity rather than frmViewPersonnel
<%# Page Language="C#" AutoEventWireup="true" CodeFile="frmUserActivity.aspx.cs" Inherits="frmUserActivity" %>
So either you are editing the wrong .cs file, OR the wrong .aspx file ;)
EDIT
After seeing your edits, your frmUserAcitivty aspx page does not contain the grdUserActivity control. So of course it wont be found.

Problem with ajax tabcontainer

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);
}
};
}

Categories