JavaScript method not working in ASP.NET User Control - c#

I asked a question before about a JavaScript code you can see it here : How can I scroll down to a multiline TextBox's bottom line, Javascript's scrollIntoView is not working for this. Well, it was solved and the accepted answer was working.
Afterwards I had to move the code part you can see in that question to a User Control which finally looked like this :
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="LiveChatPart.ascx.cs" Inherits="BeyzamComArayuz.LiveChatUserControl.LiveChatPart" %>
<%# Register src="/LiveChatUserControl/GenelOdaFlashPart.ascx" tagname="GenelOdaFlash" tagprefix="gOF" %>
<script language="javascript" type="text/javascript">
function buttonClicked() {
// var el = document.getElementById("TxtBxOdaMesajlari");
var textBox = $get("TxtBxOdaMesajlari");
textBox.scrollTop = textBox.scrollHeight;
// $get("TxtBxOdaMesajlari").scrollIntoView("false");
}
</script>
<asp:ScriptManager ID="ScrptMngr" runat="server"></asp:ScriptManager>
<tr>
<gOF:GenelOdaFlash runat="server"></gOF:GenelOdaFlash>
<td valign="top" align="left">
<table>
</table>
</td>
<td valign="top" align="left">
<table>
<tr>
<td>
buraya imajlar gelecek - chip vs.
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="LstBxOdadakiKullanicilar" runat="server"
Width="175" Height="281" Enabled="false">
<asp:ListItem Value="1" Text="Bir"></asp:ListItem>
</asp:ListBox>
</td>
</tr>
<tr>
<td>
<asp:UpdatePanel ID="UpdtPnlButtonlar" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
<asp:Button ID="ButtonOdadanCik" runat="server" Text="Odadan Çık" Width="175" Height="22" />
<asp:Button ID="ButtonHediyeGonder" runat="server" Text="Hediye Gönder" Width="175"
Height="22" />
<asp:Button ID="ButtonFullEkran" runat="server" Text="Full Ekran" Width="175" Height="22" />
<table>
<tr>
<td>
<asp:Panel ID="PnlKontroller" runat="server" GroupingText="Kontroller"
Visible="false">
<table>
<tr>
<td>
<asp:Label ID="LblChatTuru" runat="server" Text="Ücretsiz!"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="BttnSohbetTuruDegistir" runat="server"
Width="175" Text="Sohbet Türü Değiştir"
OnClick="BttnSohbetTuruDegistir_click" />
<asp:Button ID="BttnMolaVer" runat="server"
Width="175" Text="Mola Ver" OnClick="BttnMolaVer_click" />
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="ButtonOzelSohbet" runat="server" Text="Özel Sohbet" Height="108"
Width="175" OnClick="ButtonOzelSohbet_click" />
<asp:Panel ID="PnlOzelSohbetKamera" runat="server" Visible="false">
<asp:Label ID="asd" runat="server" Text="zsa"></asp:Label>
<div id="ozelOdaKamera" style="height: auto; float: left;">
<script type="text/javascript" src="/jwplayer/swfobject.js"></script>
<script type="text/javascript">
// For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
var swfVersionStr = "11.1.0";
// <!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
var xiSwfUrlStr = "playerProductInstall.swf";
var flashvars = {};
var params = {};
params.quality = "high";
params.bgcolor = "#FFFFFF";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";
var attributes = {};
attributes.id = "uyeOzelOdaKameraFlash";
attributes.name = "uyeOzelOdaKameraFlash";
attributes.align = "middle";
swfobject.embedSWF(
"/Images/uyeOzelOdaKameraFlash.swf", "ozelOdaKamera",
"220", "150",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
// <!-- JavaScript enabled so display the flashContent div in case it is not replaced with a swf object. -->
swfobject.createCSS("#flashContent", "display:block;text-align:left;");
</script>
</div>
</asp:Panel>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="padding-left:8px;">
<asp:UpdatePanel ID="UpdtPnlMesajlar" runat="server" EnableViewState="true">
<ContentTemplate>
<table>
<tr>
<td>
<table>
<tr>
<td>
<%--<div id="satir">--%>
<asp:TextBox ID="TxtBxOdaMesajlari" runat="server"
ReadOnly="true" TextMode="MultiLine"
Height="100" Width="350">
</asp:TextBox>
<%--</div>--%>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TxtBxMesaj" runat="server" Width="285"></asp:TextBox>
<%--this is the button which should run the javascript function--%>
<asp:Button ID="BttnGonder" runat="server" Text="Gönder"
Width="58" OnClick="BttnGonder_click"/>
</td>
</tr>
</table>
</td>
<td valign="top">
<asp:Panel ID="PnlAktiviteKayitlari" runat="server"
Visible="false" GroupingText="Aktivite Kayıtları">
<table>
<tr>
<td valign="top">
<asp:ListBox ID="LstBxAktiviteKayitlari" runat="server"
Enabled="false" Width="128">
<asp:ListItem Value="1" Text="Bir giriş yaptı"></asp:ListItem>
</asp:ListBox>
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
And in asp.cs file I have
protected void BttnGonder_click(object sender, EventArgs e)
{
string cariId = "";
if (KullaniciTuru == 1)
{
cariId = Session["ModelId"].ToString();
}
else
{
cariId = Session["UyeId"].ToString();
}
string uyeHesapAdi = BAL.Cari.Cari.GetCariHesapAdi(int.Parse(cariId));
string mesaj = uyeHesapAdi + " : " + TxtBxMesaj.Text;
TxtBxOdaMesajlari.Text = TxtBxOdaMesajlari.Text + Environment.NewLine + mesaj;
//TxtBxOdaMesajlari.Focus();
ScriptManager.RegisterStartupScript(this, this.GetType(), "txtbxmesajlarslide", "buttonClicked();", true);
TxtBxMesaj.Text = string.Empty;
}
My problem is that buttonClicked() function is not working anymore, I tried to use Page.ClientScriptManager.RegisterClientScriptInclude from ScottS's answer and also this Page.ClientScript.RegisterClientScriptBlock, neither of them worked.What can I do?
EDIT: I tried to debug the webpage with IE9's built in debugger and put a breakpoint in the buttonClicked() function but it was never hit.Then I used the OnClientClick event of the button and added buttonClicked function to it it works for each click but then textbox just jumps back to where it was before buttonClicked() function.

The issue is that ids for controls on a user control are somewhat mangled in that they include the user control's id plus the actual control's id. So your control's id probably looks something like: ucLiveChatPart_TxtBxOdaMesajlari.
The easy way to handle this is to change this line:
var textBox = $get("TxtBxOdaMesajlari");
to:
var textBox = document.getElementById('<%= TxtBxOdaMesajlari.ClientID %>');
Now, if you extract your javascript into a separate file or you want to use a different approach, you can emit the control id into a javascript variable from codebehind and use that instead.
In codebehind:
ScriptManager.RegisterStartupScript(this, this.GetType(), "TxtBxOdaMesajlariId", "var m_TxtBxOdaMesajlariId = '" + TxtBxOdaMesajlari.ClientID + "'";, true);
and in javascript:
var textBox = $get(m_TxtBxOdaMesajlariId);

Related

Having Issues with using VISIBLE. My Javascript doesnt seem to be handling the event when the check box is clicked

All of my hidden fields have ID's. And in my JavaScript in trying to set the visible from false to true on the payment selection. The Cash payment should just display the address to be sent to. The credit card payment comes up with text boxes and labels in order to process the payment online. But when I run the script the wont appear with the checkbox selection. I assigned an onClick event and still doesnt work. Any suggestions?
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="ShoppingCart.aspx.cs" Inherits="ShoppingCart" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<head>
<script type="text/javascript">
function paymentFunction() {
if (document.getElementById("rbCash").checked) {
document.getElementById("lbCash").visible = true;
document.getElementById("lbCash2").visible = true;
document.getElementById("lbCash3").visible = true;
document.getElementById("lbCash4").visible = true;
}
else
{
if(document.getElementById("rbCreditCard").checked)
{
document.getElementById("lbCard").visible = true;
document.getElementById("lbCardNum").visible = true;
document.getElementById("lbCVV").visible = true;
document.getElementById("lbexp").visible = true;
document.getElementById("ddlCard").visible = true;
document.getElementById("tbCnum").visible = true;
document.getElementById("tbcvvnum").visible = true;
document.getElementById("tbexp").visible = true;
}
}
}
</script>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 100%;
}
.style3
{
width: 130px;
}
</style>
</head>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<table class="style2">
<tr>
<td class="style3">
Payment Type:</td>
<td>
<asp:CheckBox ID="rbCash" runat="server" onClick="paymentFunction()" Text="Cash" ClientIDMode="Static"/>
<asp:CheckBox ID="rbCreditCard" runat="server" onClick="paymentFunction()" Text="Credit Card" />
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
<asp:Label ID="lbCash" runat="server" ForeColor="Black"
Text="Please Send Payment To:" Visible="False" ClientIDMode="Static"></asp:Label>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
<asp:Label ID="lbCash2" runat="server" ForeColor="Black"
Text="Wild Style Shoes" Visible="False" ClientIDMode="Static"></asp:Label>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
<asp:Label ID="lbCash3" runat="server" ForeColor="Black"
Text="1808 West Avenue" Visible="False" ClientIDMode="Static"></asp:Label>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
<asp:Label ID="lbCash4" runat="server" ForeColor="Black"
Text="Chicago, IL 88947" Visible="False" ClientIDMode="Static"></asp:Label>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="lbcard" runat="server" Text="Card Type" Visible="False"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlCard" runat="server" Visible="False">
<asp:ListItem>Select A Card</asp:ListItem>
<asp:ListItem>Visa</asp:ListItem>
<asp:ListItem>Discover</asp:ListItem>
<asp:ListItem>MasterCard</asp:ListItem>
<asp:ListItem>American Express</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="lbcardnum" runat="server" Text="Card Number:" Visible="False"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbCnum" runat="server" Visible="False" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="lbCVV" runat="server" Text="CVV Number" Visible="False"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbcvvnum" runat="server" Visible="False" Width="58px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="lbexp" runat="server" Text="Expiration Date" Visible="False"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbexp" runat="server" Visible="False"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Submit Payment" Visible="False" />
</td>
</tr>
</table>
<p>
</p>
<p>
</p>
<p>
Thank You For Shopping With Us:<br />
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
</asp:Content>
If you set Visible = false on the server side like you are doing, then the server will not render the control.
You probably want to do the following:
<asp:Label ID="lbCash" runat="server" ForeColor="Black"
Text="Please Send Payment To:" style="visibility:hidden" ClientIDMode="Static"></asp:Label>
Then in the javascript do something like this:
document.getElementById('lbCash').style.visibility = 'visible';

Setting selected value of RadioButtonList does not work as expected

I have a div, which is shown or hidden on the basis of some condition. In that Div I have some code as below
<div id="addPopUp" runat="server" style="padding: 30px; height: auto; width: 450px;
overflow: hidden; display: none; background-color: White; border: 1px solid black;">
<table width="500px;">
<tr>
<td valign="top" align="left" style="width: 27%;">
<input type="hidden" runat="server" id="hfLevel" />
<input type="hidden" runat="server" id="hfLevel1Id" />
<input type="hidden" runat="server" id="hfLevel2Id" />
<input type="hidden" runat="server" id="hfLevel3Id" />
</td>
<td style="width: 80%;">
</td>
</tr>
<tr>
<td style="width: 20%;" align="left" class="topics">
</td>
<td style="width: 80%;">
<asp:RadioButtonList ID="rbtnMode" runat="server" RepeatDirection="Horizontal" CssClass="mylist"
AutoPostBack="true" OnSelectedIndexChanged="rtbnMode_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="Add">Add Link</asp:ListItem>
<asp:ListItem Value="Edit">Edit Link</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td style="width: 20%;" align="left" class="topics">
<strong>Link Name :</strong>
</td>
<td style="width: 80%;">
<asp:TextBox ID="txtLinkName" CssClass="txtbox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 20%;" class="topics">
<strong>Url :</strong>
</td>
<td style="width: 80%;">
<asp:TextBox ID="txtUrl" CssClass="txtbox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 20%;" class="topics">
<strong>Position :</strong>
</td>
<td style="width: 80%;">
<asp:TextBox ID="txtPosition" CssClass="txtbox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 20%;" class="topics">
<strong>Show on same page :</strong>
</td>
<td style="width: 80%;">
<asp:CheckBox ID="chkSamePage" runat="server" Checked="true" />
</td>
</tr>
<tr>
<td>
</td>
<td class="topics" align="left">
<asp:Button ID="btnSave" runat="server" Text="Save" CssClass="sfCustomButton" OnClick="btnSave_Click" />
<asp:Button ID="btnHide" runat="server" Text="Hide Link" CssClass="sfCustomButton"
Visible="false" />
<input type="button" id="btnCancel" value="Cancel" class="sfCustomButton" onclick="hide()" />
</td>
</tr>
</table>
</div>
out of which Main Code comes here
<asp:RadioButtonList ID="rbtnMode" runat="server" RepeatDirection="Horizontal" CssClass="mylist"
AutoPostBack="true" OnSelectedIndexChanged="rtbnMode_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="Add">Add Link</asp:ListItem>
<asp:ListItem Value="Edit">Edit Link</asp:ListItem>
</asp:RadioButtonList>
Here is some Javascript code:
function showPopUp(Level, Level1Id, Level2Id, Level3Id, id) {
var radAddEdit = document.getElementById('<%=rbtnMode.ClientID %>');
var radio = radAddEdit.getElementsByTagName("input");
for (var i = 0; i < radio.length; i++) {
if (radio[i].value == 'Add') {
radio[i].checked = true;
}
}
document.getElementById("txtLinkName").value = '';
document.getElementById("txtUrl").value = '';
document.getElementById("txtPosition").value = '';
document.getElementById("chkSamePage").checked = true;
document.getElementById("hfLevel").value = Level;
document.getElementById("hfLevel1Id").value = Level1Id;
document.getElementById("hfLevel2Id").value = Level2Id;
document.getElementById("hfLevel3Id").value = Level3Id;
document.getElementById("hfEditableId").value = id;
Popup.showModal('addPopUp', null, null, { 'screenColor': '#cccccc', 'screenOpacity': .6 });
}
function hide() {
Popup.hide('addPopUp');
}
// function BindEvents() {
$(document).ready(function () {
var hf = document.getElementById("hfShow");
if (hf.value == "1") {
Popup.showModal('addPopUp', null, null, { 'screenColor': '#cccccc', 'screenOpacity': .6 });
}
});
Function ShowPopUp is called on a link to show Div and resetting it values.
Hide is called from btnCalcel to hide Div.
document.ready() is called to show Div on some condition.
Code Behind
protected void rtbnMode_SelectedIndexChanged(Object sender, EventArgs e)
{
if (rbtnMode.SelectedValue == "Edit")
{
CatalystEntities context = new CatalystEntities();
btnHide.Visible = true;
btnSave.Visible = false;
hfShow.Value = "1";
string editValue = hfEditableId.Value;
string levelNumber = editValue.Substring(0, 6);
long id = Convert.ToInt64(editValue.Substring(6));
if (levelNumber.Contains("1"))
{
var linkInfo = context.Navigation_level1.
Where(i => i.LinkID == id)
.Select(i => new
{
i.LinkName,
i.Position,
i.Url
}).FirstOrDefault();
txtLinkName.Text = linkInfo.LinkName;
txtPosition.Text = linkInfo.Position.ToString();
txtUrl.Text = linkInfo.Url;
}
}
else
{
btnSave.Visible = true;
btnHide.Visible = false;
hfShow.Value = "1";
txtLinkName.Text = String.Empty;
txtPosition.Text = String.Empty;
txtUrl.Text = String.Empty;
}
}
PROBLEM
when I open div, go to Edit radio, it works fine. But when I click on btnHide (Remember, current selection is EDIT radio button) and click on other link. ShowPopUp() get called and it resets all controls, BUT when I click on EDIT Radio it do not postback, I click on ADD Radio, it does, Now if I click on EDIT, it does.
Means, if popup is hidden with selected value Edit it doesnot postback for first time when I select Edit radio.
Please ask me if its unclear.
Thanks
You might want to consider setting the AutoPostBack property of the control to false through the properties window or C#.
There are already post like yours, here is one with the same issue.
Radiobuttonlist event not always firing
The reason for the difference in actual vs. expected behavior is most likely you have not wrapped your div that has the ID "addPopUp" in an update panel. You can view an example of that below with example panel ID's. Alternativly you could also wrap just your radio button list with an update panel and not include the other controls in the update panel.
Read the documentation on update panels from microsoft here.
<asp:UpdatePanel ID="addPopUpUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="addPopUpPanel" runat="server">
<div id="addPopUp" runat="server" style="...">
<!-- addPopUp contents -->
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>

Asynchronously extend multiple CollapsiblePanels

I have a webpage that is setup like so:
There is a ListView that has an item for each record in one of our SQL tables. Each of these items has a CollapsiblePanel in it that can be expanded to show more detail about the given record.
My Issue:
When I expand one panel and then wait for it to complete...everything is okay. However, if I try to expand multiple of those collapsiblepanels at once (meaning before the first panel is completely expanded)...only the last panel expands showing its data.
My Question:
Is it possible to have each of these panels expand asynchronously? Seems silly that I have to wait for one panel to extend before I can extend another.
My aspx:
I modified this aspx a little bit by removing unneeded code to make it less confusing.
<asp:UpdatePanel ID="UpdPnlBGList" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<div class="content-box">
<asp:Panel ID="pnlBGResult" runat="server">
<asp:ListView ID="lvSummary" runat="server" ItemPlaceholderID="placeholderBGList"
OnItemDataBound="lvSummary_ItemDataBound" OnItemCommand="lvSummary_ItemCommand">
<LayoutTemplate>
<table runat="server" id="tblList" cellpadding="0" cellspacing="0" border="0" style="table-layout: fixed;">
<tr id="placeholderBGList" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:UpdatePanel ID="UpdBgItemTemplate" runat="server" ChildrenAsTriggers="true"
UpdateMode="Conditional">
<ContentTemplate>
<div class="bgList">
<asp:Panel ID="pnlSummary" runat="server">
<table id="tblBgList" runat="server" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse;
border-spacing: 0px;">
<tr>
<td class="imageColumn">
<asp:ImageButton ID="imgCollapsible" CssClass="first" ImageUrl="~/Images/branding/plus.gif"
runat="server" CommandName="ExpandCollapse" Style="cursor: pointer; padding-right: 5px;" />
</td>
<td width="600px">
<asp:Label ID="lblBGName" runat="server" Text='<%# Eval("BGName")%>' CssClass="bgName"></asp:Label>
<asp:Label ID="lblDatePosted" runat="server" CssClass="datePosted"></asp:Label>
</td>
<td colspan="2">
<div style="float: right;">
<asp:Label ID="lblAccountNumber" runat="server" CssClass="accountReview"></asp:Label>
<asp:Label ID="lblAccountNumberText" runat="server" CssClass="accountReview"></asp:Label>
</div>
</td>
</tr>
<tr>
<td>
</td>
<td width="600px">
<asp:Label ID="lblBillToAddress" runat="server" Text='<%# Eval("BillToAddress")%>'
CssClass="billToAddress" Style="font-weight: bold;"></asp:Label>
</td>
<td>
<div style="float: right;">
<asp:ImageButton ID="imgViewAuthLetter" ImageUrl="~/Images/branding/document.jpeg"
CssClass="first" runat="server" OnClick="imgViewAuthLetter_Click" />
<asp:LinkButton ID="lnkAuthorizationLetter" runat="server" Text="View authorization letter"
class="link_button" OnClick="lnkAuthorizationLetter_Click" OnClientClick="dirtySuppress();"
OnPreRender="addTrigger_PreRender" />
</div>
</td>
<td width="70px" style="float: right;">
<div style="float: right;">
<asp:HyperLink ID="lnkExportImage" runat="server" ImageUrl="/Images/branding/export.jpg"
CssClass="hiperlinkExport" OnClick="dirtySuppress();" />
<asp:HyperLink ID="lnkExportText" runat="server" Text="Export" CssClass="hiperlinkExport"
OnClick="dirtySuppress(); precheckURL(this.href); return false;" />
</div>
</td>
</tr>
<tr>
<td colspan="4" style="padding: 0px;">
<asp:Panel Style="margin-left: 50px;" ID="pnlDetails" runat="server">
<of:AccountNumberListControl ID="accountNumberList" runat="server"></of:AccountNumberListControl>
</asp:Panel>
<cc1:CollapsiblePanelExtender ID="cpe" runat="Server" TargetControlID="pnlDetails"
CollapsedSize="0" Collapsed="True" ExpandControlID="imgCollapsible" CollapseControlID="imgCollapsible"
AutoCollapse="False" AutoExpand="False" ScrollContents="false" ImageControlID="imgCollapsible"
ExpandedImage="~/Images/branding/minus.gif" CollapsedImage="~/Images/branding/plus.gif"
ExpandDirection="Vertical" />
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3" style="padding: 0px;">
<div class="itemSeperator" id="divItemSeperator" runat="server">
</div>
</td>
</tr>
</table>
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:HiddenField ID="hdfAccountNumberListControlID" runat="server" Value="" />
<asp:HiddenField ID="hdfAccountNumerID" runat="server" Value="" />
</asp:Panel>
</div>
<of:CustomerSetupExportPopInControl ID="customerSetupExportPopIn" runat="server" />
</ContentTemplate>
My codebehind:
This is the code that is executed when you expand the panel. There are several controls that is populated.
private void ExpandBillingGroup(ListViewDataItem item)
{
Label accountNumberLabel;
Label accountNumberText;
HtmlControl itemSeperator;
AccountNumberListControl accountNumberList;
// set properties for fedex account number label and text.
accountNumberLabel = (Label)item.FindControl("lblAccountNumber");
accountNumberLabel.Text = "FedEx account number: ";
accountNumberLabel.CssClass = "fedExAccountNumberLabel";
accountNumberText = (Label)item.FindControl("lblAccountNumberText");
accountNumberText.Text = lvSummary.DataKeys[item.DisplayIndex].Values["FedExAccountNumber"].ToString();
accountNumberText.CssClass = "fedExAccountNumberText";
//set the properties for Export
var lnkExportImage = (HyperLink)item.FindControl("lnkExportImage");
lnkExportImage.Visible = true;
var lnkExportText = (HyperLink)item.FindControl("lnkExportText");
lnkExportText.Visible = true;
//When expanded populate Customer Setup Export control
customerSetupExportPopIn.BillingGroupID = lvSummary.DataKeys[item.DisplayIndex].Values["BillingGroupID"].ToString();
//When expanded populate AccountNumberlistControl
accountNumberList = (AccountNumberListControl)item.FindControl("accountNumberList");
if (accountNumberList != null)
{
//since we make the AccountNumberListControl not visible on collapse we have to make it visible when we expand
accountNumberList.Visible = true;
//Set the properties
accountNumberList.BillingGroupID = lvSummary.DataKeys[item.DisplayIndex].Values["BillingGroupID"].ToString();
accountNumberList.FedExAccountNumber = lvSummary.DataKeys[item.DisplayIndex].Values["FedExAccountNumber"].ToString();
accountNumberList.BillingGroupName = ((Label)lvSummary.Items[item.DisplayIndex].FindControl("lblBGName")).Text;
accountNumberList.BillToAddress = ((Label)lvSummary.Items[item.DisplayIndex].FindControl("lblBillToAddress")).Text;
accountNumberList.FirstItemNeedsToExpand = BillingGroupIsResolved;
accountNumberList.GetListOfAccountNumbers(lvSummary.DataKeys[item.DisplayIndex].Values["BillingGroupID"].ToString(), VendorID);
}
//set the properties for itemSepeartor
itemSeperator = (HtmlControl)item.FindControl("divItemSeperator");
itemSeperator.Attributes.Add("class", "itemSeperatorExpanded");
UpdatePanel upd = (UpdatePanel)item.FindControl("UpdBgItemTemplate");
upd.Update();
}
Thanks,
Holt
EDIT: Fixed grammar and title issues

Adding Form Validation to ADFS Login

I need to add a check for form variables that are passed to my adfs login page but when I add anything to the built-in Page_Load function it breaks.
FormsSignIn.aspx
<%# Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" ValidateRequest="false"
CodeFile="FormsSignIn.aspx.cs" Inherits="FormsSignIn" Title="<%$ Resources:CommonResources, FormsSignInPageTitle%>"
EnableViewState="false" runat="server"%>
<%# OutputCache Location="None" %>
<asp:Content ID="FormsSignInContent" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="GroupXLargeMargin"><asp:Label Text="<%$ Resources:CommonResources, FormsSignInHeader%>" runat="server" /></div>
<h3>*******I Want lbl1.Text to output here from the codefile.</h3>
<table class="UsernamePasswordTable">
<tr>
<td>
<span class="Label"><asp:Label Text="<%$ Resources:CommonResources, UsernameLabel%>" runat="server" /></span>
</td>
<td>
<asp:TextBox runat="server" ID="UsernameTextBox" ></asp:TextBox>
</td>
<td class="TextColorSecondary TextSizeSmall">
<asp:Label Text="<%$ Resources:CommonResources, UsernameExample%>" runat="server" />
</td>
</tr>
<tr>
<td>
<span class="Label"><asp:Label Text="<%$ Resources:CommonResources, PasswordLabel%>" runat="server" /></span>
</td>
<td>
<asp:TextBox runat="server" ID="PasswordTextBox" TextMode="Password" ></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td></td>
<td colspan="2" class="TextSizeSmall TextColorError">
<asp:Label ID="ErrorTextLabel" runat="server" Text="" Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<div class="RightAlign GroupXLargeMargin">
<asp:Button ID="SubmitButton" runat="server" Text="<%$ Resources:CommonResources, FormsSignInButtonText%>" OnClick="SubmitButton_Click" CssClass="Resizable"/>
</div>
</td>
<td> </td>
</tr>
</table>
</asp:Content>
FormsSignIn.Aspx.cs
using System;
using Microsoft.IdentityServer.Web;
using Microsoft.IdentityServer.Web.UI;
public partial class FormsSignIn : FormsLoginPage
{
protected void Page_Load( object sender, EventArgs e )
{
//Uncommented, this breaks!!!!!!!!!!!!!!
/* if ( !string.IsNullOrEmpty(Page.Request.Form["foo"]) ) {
lbl1.Text = Page.Request.Form["foo"].Trim();
} else {
lbl1.Text = "not found";
} */
}
protected void HandleError( string message )
{
ErrorTextLabel.Visible = true;
ErrorTextLabel.Text = Resources.CommonResources.IncorrectUsernameText;
}
protected void SubmitButton_Click( object sender, EventArgs e )
{
try
{
SignIn( UsernameTextBox.Text, PasswordTextBox.Text );
}
catch ( AuthenticationFailedException ex )
{
HandleError( ex.Message );
}
}
}
You haven't mentioned how you added the code or how it breaks but, in general, I have found problems when I modify the files directly.
Given that ADFS is just another IIS application, I have more joy following this approach:
Modifying and Securing the ADFS 2 Web Application

Master page popup login control using ajaxcontroltoolkit don't work

I made a pop control on the master page in asp.net 3.5
please see the following code:
Main.master aspx code:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Panel ID="Panel1" runat="server"
style="display:none; background-color:White; width:700;
border-width:2px; border-color:Black; border-style:solid;
padding:20px;">
<table width="100%" border="0" cellpadding="2" cellspacing="5">
<tr>
<td><asp:Label id="labMsg" runat="server" ForeColor="Red"EnableViewState="false" />
</td>
</tr>
<tr>
<td>
<strong>Login ID :</strong>
<asp:TextBox ID="txtLogin" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td><strong>Password :</strong>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnOk" runat="server" Text="Sign In" onclick="Login" />
<asp:Button ID="btnClose" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="defaultPanel" CssClass="Default_Panel" runat="server" Visible="true">
<ul><li><asp:LinkButton ID="lnkSignIn" class="last" runat="server" Visible="true" Text="sign in"></asp:LinkButton>
<asp:LinkButton ID="lnkSignOut" class="last" runat="server" Visible="false" Text="sign out"></asp:LinkButton>
</li>
</ul>
<!-- Login Pop Ajax Control Tool Kit -->
<ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1"
runat="server" TargetControlID="lnkSignIn"
DisplayModalPopupID="ModalPopupExtender1">
</ajaxToolkit:ConfirmButtonExtender>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
CancelControlID="btnClose" OkControlID="btnOk"
PopupControlID="Panel1"
TargetControlID="lnkSignIn">
</ajaxToolkit:ModalPopupExtender>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
Main.master.cs code:
public void Login(object sender, EventArgs e)
{
// return "Login Successfull";
labMsg.Text = "Login Successfull";
}
Problem:
When login button is pressed[from Default.aspx or from any other child page] it don't hit the Login method on the master page. Help is appreciated.
I have managed to solve the problem here is the code:
Master.master:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="defaultPanel" CssClass="Default_Panel" runat="server" Visible="true">
<ul id="loginLinks">
<li><asp:LinkButton ID="lnkSignIn" class="last" runat="server" Visible="true" Text="sign in"></asp:LinkButton></li>
</ul>
<!-- Login Pop Ajax Control Tool Kit -->
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" CancelControlID="btnClose" PopupControlID="pnlSignIn" TargetControlID="lnkSignIn"></ajaxToolkit:ModalPopupExtender>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="pnlSignIn" runat="server">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table width="100%" border="0" cellpadding="2" cellspacing="5">
<tr>
<td style="width: 35%; padding-top: 50px;">
</td>
<td>
<asp:Label ID="labMsg" runat="server" ForeColor="Red" EnableViewState="false" />
</td>
</tr>
<tr>
<td align="right" valign="middle">
<strong>Login ID :</strong>
</td>
<td>
<asp:TextBox ID="txtLogin" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" valign="middle">
<strong>Password :</strong>
</td>
<td>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnOk" runat="server" Text="Sign In" OnClick="btnOk_Click" />
<asp:Button ID="btnClose" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
Note: 2 update panels now, removed confirmbuttonextender.
I really don't know why the login method wasn't hitting before and how come it's working now.
Master.master.cs:
protected void btnOk_Click(object sender, EventArgs e)
{
var name = txtLogin.Text;
var pwd = txtPassword.Text;
DataSet ds = new DataSet();
string userName = name;
string pwdBeforeConversion = pwd;
//Encryption of pasword
SHA1CryptoServiceProvider x = new SHA1CryptoServiceProvider();
byte[] data = Encoding.ASCII.GetBytes(pwdBeforeConversion);
data = x.ComputeHash(data);
//pass the data to service, and get a return as dataset
try
{
somelogic here
}
catch (Exception ex3)
{
if (ex3.Message == "InvalidUsernameOrPassword")
labMsg.Text = "sorry user name and password could not be found";
else if (ex3.Message == "EmailNotVerified")
labMsg.Text = "please contact ta; email is not verified";
else if (ex3.Message == "AccountDisabled")
labMsg.Text = "please contact ta; account is not verified";
else
labMsg.Text = "sorry we encounterd a techncal issue, please try logging in again";
ModalPopupExtender1.Show();
return;
}
}

Categories