Update dropdownlist on a Panel - c#

I have two dropDownLists in a Panel that pops up. When i change one value in the first dropDownList i want to populate the seconde dropDownList with the value chosen in the first dropDownList. Like i have AutoPostBack = "true" the page is always refreshing and the PopUp disappears. When in fact i only want to update the panel on the PopUp.
I´m using AsyncPostBackTrigger.
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup"
PopupControlID="pnlpopup" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="199px" Width="400px"
Style="display: none">
<table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%"
cellpadding="5" cellspacing="0">
<tr style="background-color: #D55500">
<td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
align="center">
Insert Product
</td>
</tr>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<tr>
<td align="right" style="width: 45%">
Category:
</td>
<td>
<asp:DropDownList AutoPostBack="true" runat="server" ID="DropDownList1" OnSelectedIndexChanged="dropDownList_Change" />
</td>
</tr>
<tr>
<td align="right">
Product:
</td>
<td>
<asp:DropDownList id="DropDownList2" runat="server">
</asp:DropDownList>
</td>
</tr>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<tr>
<td>
</td>
<td>
<asp:Label ID="popup_modo" runat="server" Visible="false"></asp:Label>
<asp:Button ID="btnCommand" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>

Try this:
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="199px" Width="400px"
Style="display: none">
<table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%"
cellpadding="5" cellspacing="0">
<tr style="background-color: #D55500">
<td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
align="center">
Insert Product
</td>
</tr>
<tr>
<td align="right" style="width: 45%">
Category:
</td>
<td>
<asp:DropDownList AutoPostBack="true" runat="server" ID="DropDownList1" OnSelectedIndexChanged="dropDownList_Change" />
</td>
</tr>
<tr>
<td align="right">
Product:
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList id="DropDownList2" runat="server">
</asp:DropDownList></ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="popup_modo" runat="server" Visible="false"></asp:Label>
<asp:Button ID="btnCommand" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>

I had the similar problem and the key was in the part where I set the Items do Dropdown. When you set these Items it select the first one after page reload (with autopostback).
If this is your problem try this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillDropDown();
}
}

Related

How to control button from panel

I am new to ASP.NET. I have taken a Panel. Inside the Panel, I have taken a table. Inside the table there are TextBox, RadioButton and a Button controls.
I have written some code in button_click event.
But nothing happens. button_click event is not firing.
What to do now ?
I have also some other things in panel. But no click event is working.
Code is below:
<asp:Panel ID="Pnlproducts" runat="server" ScrollBars="Auto" Height="500px" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<asp:DataList ID="DLProducts" runat="server" RepeatColumns="3" Width="600px" OnSelectedIndexChanged="DLProducts_SelectedIndexChanged">
<ItemTemplate >
<table align="left" class="auto-style6" style="border-color:#9900FF;border-left:1px;border-right:1px;border-top:1px;">
<tr>
<td style="border-color: #000000; border-width: 1px; border-bottom-style: ridge" class="auto-style8">
<asp:Label ID="lblProductName" runat="server" Text="<%# Bind('ProductName') %>" Font-Bold="True"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style9">
<asp:Image ID="Image2" runat="server" Height="160px" ImageUrl="<%# Bind('ProductImage') %>" Width="173px" Style="border:ridge 1px black" />
</td>
</tr>
<tr>
<td class="auto-style9"><strong>Price:</strong><asp:Label ID="lblPrice" runat="server" Text="<%# Bind('ProductPrice') %>" Font-Bold="True" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style9">
<asp:Button ID="Addtocartbtn" runat="server" BorderStyle="Solid" BorderWidth="1px" OnClick="Addtocartbtn_Click" Text="Add to Cart" Width="170px" BorderColor="Black" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</asp:Panel>
<asp:Panel ID="Panel111" runat="server" ScrollBars="Auto" Height="500px" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<table class="auto-style16">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlCatagory" runat="server" Height="500px" ScrollBars="Auto" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<div class="auto-style7">
<asp:DataList ID="dlCatagory" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<ItemTemplate>
<asp:LinkButton ID="LBTNCatagoty" runat="server" CommandArgument="<%# Bind('CatagoryID') %>" Font-Bold="True" OnClick="LBTNCatagoty_Click" Text="<%# Bind('CatagoryName') %>"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</div>
</asp:Panel>
<asp:Panel ID="Panel222" runat="server" Height="500px" ScrollBars="Auto" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<table class="auto-style10">
<tr>
<td class="auto-style7" colspan="2"><strong>Please Type Your Details</strong></td>
</tr>
<tr>
<td class="auto-style12"></td>
<td class="auto-style11"></td>
</tr>
<tr>
<td class="auto-style15">Name :</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxUserName" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">E-mail :</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxEmail" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Address:</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxAdress" runat="server" Height="90px" TextMode="MultiLine" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Gender :</td>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="GenderGroup" Text="Male" /><br />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="GenderGroup" Text="Female" />
</td>
</tr>
<tr>
<td class="auto-style15">Mobile:</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxMobileNum" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Photo :</td>
<td class="johnykbd8">
<asp:FileUpload ID="FileUploaduserphoto" runat="server" Width="180px" />
</td>
</tr>
<tr>
<td class="auto-style15">Payment :</td>
<td>
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="Paymentgroup" Text="Visa" /><br />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="Paymentgroup" Text="MasterCard" /><br />
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="Paymentgroup" Text="Cash On Delivery" />
</td>
</tr>
<tr>
<td class="auto-style15">Review :</td>
<td>
<asp:TextBox ID="TextBoxreview" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Total : </td>
<td>BDT :<asp:Label ID="Labelshopamount" runat="server"></asp:Label></td>
</tr>
<tr>
<td colspan="2">
<asp:ImageButton ID="ImageButtonOrderNow" runat="server" ImageUrl="~/Images/Designing/order.jpg" OnClick="ImageButtonOrderNow_Click" Width="250px" />
</td>
</tr>
</table>
</asp:Panel>
If the button is in a datalist or gridview for example, set the CommandName property. The databound object (datalist, gridview) has ItemCommand-event. Put the code in this event.
Pseudo code:
if (e.CommandName.equals(your_command_name)){ label1.text = e.CommandArgument };

Button in Modal Popup Is not working as it should have to worked

I am Having a code for Modal PopUp windoe in which I wanna perform login operation and code for extender is as follows.
<div class="wrapper">
<ul id="icons">
<li><asp:ImageButton runat="server" ImageUrl="images/lgn.png" ID="btnimg" CssClass="image" /></li>
</ul>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnimg" PopupControlID="Panel1" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender >
<asp:panel id="Panel1" CssClass="popup" runat="server">
<div class="popup">
<div id="PopupHeader" style="height:55px;background-color:#f6f6f6;border-radius:10px;width:348px;font-size:2.7em; "> <font style="margin:30px 0px 0px 20px;vertical-align:middle;color:Black;line-height:1.2em; font-size:37px; font-family: BonvenoCF;"> Login </font></div>
<div class="PopupBody">
<table width="350px" style="vertical-align:middle;text-align:center;">
<tr>
<td style="width:43.5px"> </td>
<td style="width:131.25px"> </td>
<td style="width:131.25px"> </td>
<td style="width:43.5px"> </td>
</tr>
<tr>
<td style="width:43.5px"> </td>
<td style="width:131.25px">
<asp:Label ID="Label1" runat="server" Text="User Name: "></asp:Label>
</td>
<td style="width:131.25px">
<asp:TextBox ID="txtUserName" runat="server" Height="20px" style="border-radius:8px;"> </asp:TextBox>
<asp:TextBoxWatermarkExtender ID="txtUserName_TextBoxWatermarkExtender" runat="server" Enabled="True" TargetControlID="txtUserName"WatermarkText="User Name">
</asp:TextBoxWatermarkExtender>
</td>
<td style="width:43.5px"> </td>
</tr>
<tr>
<td style="width:43.5px"> </td>
<td style="width:131.25px"> </td>
<td style="width:131.25px"> </td>
<td style="width:43.5px"> </td>
</tr>
<tr>
<td style="width:43.5px"> </td>
<td style="width:131.25px">
<asp:Label ID="Label2" runat="server" Text="Password: " ></asp:Label>
</td>
<td style="width:131.25px">
<asp:TextBox ID="txtPassword" runat="server" Height="20px" style="border-radius:8px;"> </asp:TextBox>
<asp:TextBoxWatermarkExtender ID="txtPassword_TextBoxWatermarkExtender"
runat="server" Enabled="True" TargetControlID="txtPassword"
WatermarkText="Password">
</asp:TextBoxWatermarkExtender>
</td>
<td style="width:43.5px"> </td>
</tr>
<tr>
<td style="width:43.5px"> </td>
<td colspan="2">
<asp:Label ID="Label3" runat="server" Text="Invalid User Name Or Password." Visible="False"></asp:Label>
</td>
<td style="width:43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:Button ID="Button2" runat="server" CssClass="button" Text="Login" />
</td>
<td style="width: 131.25px">
<asp:Button ID="Button1" runat="server" CssClass="button" Text="Cancle" /></td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:LinkButton ID="LinkButton1" runat="server">Forgot Password</asp:LinkButton>
</td>
<td style="width: 131.25px">
<asp:Button ID="Button3" runat="server" CssClass="button" Text="Sign Up" />
</td>
<td style="width: 43.5px"> </td>
</tr>
</table>
</div>
</div>
</asp:panel>
</div>
on button2_Click code behind is as follows.
protected void Button2_Click(object sender, EventArgs e)
{
ds = obj.sel("select UserName and Password from tblUserMaster where UserName='"+txtUserName.Text+"' AND Password='"+txtPassword.Text+"'");
if (ds.Tables[0].Rows.Count == 0)
{
Label3.Visible = true;
}
else
{
Response.Redirect("Default.aspx");
}
}
But when i'm clicking on LOGIN Button it is not redirection me on Default.aspx page popup is getting closed.
while on clicking on cancel button it is not working at all.
please suggest an solution as soon as possible.
use update panel for refreshing problem .
here is complete code .
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div class="wrapper">
<ul id="icons">
<li><asp:ImageButton runat="server" ImageUrl="images/lgn.png" ID="btnimg" CssClass="image" /></li>
</ul>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnimg" PopupControlID="Panel1" BackgroundCssClass="modalBackground" CancelControlID="Button1"></asp:ModalPopupExtender>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" CssClass="popup" runat="server">
<div class="popup">
<div id="PopupHeader" style="height: 55px; background-color: #f6f6f6; border-radius: 10px; width: 348px; font-size: 2.7em;"><font style="margin: 30px 0px 0px 20px; vertical-align: middle; color: Black; line-height: 1.2em; font-size: 37px; font-family: BonvenoCF;"> Login </font></div>
<div class="PopupBody">
<table width="350px" style="vertical-align: middle; text-align: center;">
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px"> </td>
<td style="width: 131.25px"> </td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:Label ID="Label1" runat="server" Text="User Name: "></asp:Label>
</td>
<td style="width: 131.25px">
<asp:TextBox ID="txtUserName" runat="server" Height="20px" Style="border-radius: 8px;"> </asp:TextBox>
</td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px"> </td>
<td style="width: 131.25px"> </td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:Label ID="Label2" runat="server" Text="Password: "></asp:Label>
</td>
<td style="width: 131.25px">
<asp:TextBox ID="txtPassword" runat="server" Height="20px" Style="border-radius: 8px;"> </asp:TextBox>
<asp:TextBoxWatermarkExtender ID="txtPassword_TextBoxWatermarkExtender"
runat="server" Enabled="True" TargetControlID="txtPassword"
WatermarkText="Password">
</asp:TextBoxWatermarkExtender>
</td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td colspan="2">
<asp:Label ID="Label3" runat="server" Text="Invalid User Name Or Password." Visible="False"></asp:Label>
</td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:Button ID="Button2" runat="server" CssClass="button" Text="Login" OnClick="Button2_Click" />
</td>
<td style="width: 131.25px">
<asp:Button ID="Button1" runat="server" CssClass="button" Text="Cancle" /></td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:LinkButton ID="LinkButton1" runat="server">Forgot Password</asp:LinkButton>
</td>
<td style="width: 131.25px">
<asp:Button ID="Button3" runat="server" CssClass="button" Text="Sign Up" OnClick="Button3_Click" />
</td>
<td style="width: 43.5px"> </td>
</tr>
</table>
</div>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
#Chirag : you haven't added the onclick event on your button . so please add this ..
edit your code .
<asp:Button ID="Button2" runat="server" CssClass="button" Text="Login" OnClick="Button2_Click"/>

JavaScript Function

I want to store TextBox value in HidenField and i am calling javascript function on button click function is calling getting message Hi but... textBox getting null....I am using asp.net TextBox and also i have tried with HTML textBox also but same scenario happing in both the case...Actually HTML code using in Ajax Tab Container may be this problem ...
How to solve such type of problem
function f11() {
alert("Hi")
alert("hi..." + document.getElementById("txthtmltextbox").value)
document.getElementById("txtuncheaderHF").value = document.getElementById("txthtmltextbox").value;
document.getElementById("txtrootFolderHF").value = document.getElementById("txthtmltextboxroot").value
}
This is my HTML code
<asp:Panel ID="pnlhfconfig" runat="server" Height="100%" Width="100%">
<table bordercolor="gainsboro" bgcolor="white" style="border-bottom-width: 1px; border-bottom-style: solid;
border-top-width: 1px; border-top-style: solid; border-left-width: 1px; border-left-style: solid;
border-right-width: 1px; border-right-style: solid; border-bottom-color: #8C8B83;
border-top-color: #8C8B83; border-left-color: #8C8B83; border-right-color: #8C8B83;"
id="TABLE2" language="javascript">
<tbody>
<tr>
<td colspan="3" bgcolor="#E5E5E5" height="20" class="topnav" style="font-size: 10px;
font-family: verdana">
<font style="color: #000000"><strong>
<asp:Literal ID="Literal4" runat='server' Text='HF Configuration'></asp:Literal>  </strong></font>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbluncheader" runat="server" Text='HotFolder UNCHeader'></asp:Label>
</td>
<td>
<input type="text" id="txthtmltextbox" name="txthtmltextbox" onblur="f1()" runat="server" MaxLength="50" Style="z-index: 102;" Width="250px" />
<asp:RequiredFieldValidator ID="rfvuncheader" runat="server"
ErrorMessage="UNCHeader is required." ControlToValidate="txthtmltextbox" Display="None"
ValidationGroup="save"></asp:RequiredFieldValidator>
</td>
<td>
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblrootfolder" runat="server" Text='Hot RootFolder'></asp:Label>
</td>
<td>
<input type="text" id="txthtmltextboxroot" name="txthtmltextboxroot" runat="server" MaxLength="50" Style="z-index: 102;" Width="250px" />
<%-- <asp:TextBox ID="txtrootfolder" runat="server" MaxLength="50" Width="250px"></asp:TextBox>--%><asp:RequiredFieldValidator
ID="rfvUNH" runat="server" ErrorMessage="RootFolder is required." ControlToValidate="txthtmltextboxroot"
Display="None" ValidationGroup="save"></asp:RequiredFieldValidator>
</td>
<td>
<asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="Red" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<table>
<tr>
<td>
<asp:Button ID="btnsave" OnClientClick ="f1()" runat="server" Text='Save' Width="55px" BackColor="#E5E5E5"
ForeColor="Black" ValidationGroup="save" />
</td>
<td>
<asp:Button ID="btncancel" runat="server" Text='Cancel' Width="55px" BackColor="#E5E5E5"
ForeColor="Black" />
</td>
</tr>
<tr>
<td>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False" ValidationGroup="save" />
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</asp:Panel>
Hope you aware of JQuery and using JQuery, you will easily get inner control of panel. Because when your page is render on browser. Html code is something different then .NET(ASPX page).
You will get/set panel inner control value using below statement.
$("#<%=pnlhfconfig.ClientID %> input[id='<%= txtuncheaderHF.ClientID %>']").val($("#<%=pnlhfconfig.ClientID %> input[id='<%= txthtmltextbox.ClientID %>']").val());
You are using txthtmltextbox please check on console what is the actual ID of control while generating html.
Or use as
document.getElementById("<%= txthtmltextbox.ClientID%>").value

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

Problem in using RequiredFieldValidator control in asp.net c#

I am using RequiredFieldValidator in my asp.net program. I have a sign out button which is used to terminate the session, but when i click on this sign out button without inserting any values in any of the text box the RequiredFieldValidator throws an error and i am not able to sign out.
I want to sign out a user without inputting any of the values in the textbox.
Please check my code in case of any problem in my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class EntryForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{// CHEK SESSION VARIABLE AND LOAD dropdownlist1 WITH VALUES
if (!IsPostBack)
{
String DB = "";
String AccountID = "";
if (Session["login"] != null && Session["db"] != null)
{
AccountID = Session["login"].ToString();
DB = Session["db"].ToString();
Label9.Text = AccountID;
}
else
{
Response.Redirect("log.aspx");
}
HiddenField1.Value = DB.ToString();
DropDown a = new DropDown();
a.filldropdown1(this.DropDownList1, DB);
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
// LOG OUT***********////////////
Session.Abandon();
Response.Redirect("log.aspx");
}
.aspx code
<%# Page Language="C#" AutoEventWireup="true" CodeFile="EntryForm.aspx.cs" Inherits="EntryForm" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc1" %>
<!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>
<style type="text/css">
.style1
{
width: 330px;
}
.style2
{
text-align: center;
}
.style3
{
text-align: center;
width: 38px;
}
.style4
{
text-align: center;
width: 109%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:90%; height: 30px;">
<tr>
<td class="style1">
<asp:Label ID="Label8" runat="server" style="text-align: left"
Text="Welcome"></asp:Label>
<asp:Label ID="Label9" runat="server" style="text-align: left"></asp:Label>
</td>
<td align="center" width="100%" style="text-align: right">
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click"
style="text-align: right">Log Out</asp:LinkButton>
</td>
</tr>
</table>
</div>
<table style="width:95%;" align="center" bgcolor="Silver">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Type : "></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="DropDownList1" ErrorMessage="*"
InitialValue="<-- Select -->">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text="No. :"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="75px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="*">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:Label ID="Label3" runat="server" Text="Year :"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="75px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Enter Year">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Enter year"
ValidationExpression="^\d{4}$">YYYY</asp:RegularExpressionValidator>
</td>
<td>
<asp:Label ID="Label4" runat="server" Text="Order Date : "></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" Width="75px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="TextBox3" ErrorMessage="Enter proper format">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ControlToValidate="TextBox3" ErrorMessage="Enter valid date"
ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$">dd/mm/yyyy</asp:RegularExpressionValidator>
</td>
<td>
<asp:Button ID="Button2" runat="server" Text="GO" onclick="Button2_Click" />
</td>
</tr>
</table>
<br />
<table style="width:100%;">
<tr>
<td style="text-align: center">
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
style="text-align: center" Visible="False"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
</table>
<br />
<table style="width:100%;">
<tr>
<td style="text-align: center" width="100%">
<asp:Label ID="Label5" runat="server" Text="Label" Visible="False"
style="text-align: center"></asp:Label>
</td>
<td style="text-align: center" width="100%">
<asp:Label ID="Label6" runat="server" Text="Vs" Visible="False"></asp:Label>
</td>
<td style="text-align: center" width="100%">
<asp:Label ID="Label7" runat="server" Text="Label" Visible="False"></asp:Label>
</td>
</tr>
</table>
<br />
<table style="width:100%;" border="1">
<tr>
<td class="style3" width="100%">
</td>
<td class="style4" width="100%">
<cc1:Editor ID="Editor1" runat="server" Width="60%" AutoFocus="true"
style="text-align: right" />
</td>
<td class="style2" width="100%">
</td>
</tr>
</table>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:HiddenField ID="HiddenField1" runat="server"/>
</form>
</body>
</html>
There are 2 ways you can do this
put validation group property to your controls
ValidationGroup="input"
OR
On your sign out link button, put
CausesValidation="false"
Use validation group property to group the items to be validated.
http://www.w3schools.com/ASPNET/prop_webcontrol_imagebutton_validationgroup.asp
On your Sign Out button set CausesValidation property to false
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click"
CausesValidation="False"
style="text-align: right">Log Out</asp:LinkButton>
There is a property of button CausesValidation; set it to false. Than the validations on page won't fire.

Categories