How to hide a panel by clicking on dropdown menu? - c#

I have a dropdown menu and it has a set of items.I want to hide a particular panel when i am clicking on a dropdown menu.
Below is my c# code and my panel is designed in asp.net.
I want to disable panel XII when i was clicking on dropdown list item Not Applicable in panel X
protected void ddsscboard_SelectedIndexChanged(object sender, EventArgs e)
{
try {
string sscpanel = ddsscboard.SelectedItem.Text;
panelshow(sscpanel);
}
catch(Exception ex)
{
}
}
public void panelshow(string sscpanel)
{
if (sscpanel == "Not Applicable")
XII.Visible = false;
else
lblmsg.Text = sscpanel;
}
}
panel:-
Class X
<div class="form-group">
<label>Select Board</label>
<asp:DropDownList ID="ddsscboard" CssClass="form-control" OnSelectedIndexChanged="ddsscboard_SelectedIndexChanged" runat="server">
<asp:ListItem>Not Applicable</asp:ListItem>
<asp:ListItem>SSC</asp:ListItem>
<asp:ListItem>CBSC</asp:ListItem>
<asp:ListItem>ICSC</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
</div>
<div class="form-group">
<label>Complition Month</label>
<asp:TextBox ID="txtssccomplitionmonth" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Complition Year</label>
<asp:TextBox ID="txtssccomplitionyear" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Marks Obtained</label>
<asp:TextBox ID="txtsscmarksobtained" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Total Marks</label>
<asp:TextBox ID="txtssctotalmarks" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Upload File</label>
<asp:FileUpload ID="sscfile" runat="server" />
</div>
</div>
<!-- /.col-lg-6 (nested) -->
</div>
<!-- /.row (nested) -->
</div>
</asp:Panel>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<div class="col-lg-12">
<asp:Panel ID="XII" runat="server" CssClass="panel panel-default">
<div class="panel-heading">
Class XII
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>Select Board</label>
<asp:DropDownList ID="ddhscboard" CssClass="form-control" runat="server">
<asp:ListItem>Not Applicable</asp:ListItem>
<asp:ListItem>HSC</asp:ListItem>
<asp:ListItem>CBSC</asp:ListItem>
<asp:ListItem>ICSC</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
</div>
<div class="form-group">
<label>Complition Month</label>
<asp:TextBox ID="txthsccomplitionmonth" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Complition Year</label>
<asp:TextBox ID="txthsccomplitionyear" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Marks Obtained</label>
<asp:TextBox ID="txthscmarksobtained" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Total Marks</label>
<asp:TextBox ID="txthsctotalmarks" CssClass="form-control" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label>Upload File</label>
<asp:FileUpload ID="hscfile" runat="server" />
</div>
</div>
<!-- /.col-lg-6 (nested) -->
</div>
<!-- /.row (nested) -->
</div>
</asp:Panel>
<!-- /.panel-body -->
</div>

You need to set the AutoPostBack attribute in your DropDownList to true. Note you may also want to establish a blank ListItem so "Not Applicable" is not Selected by default:
<asp:DropDownList AutoPostBack="true" ID="ddsscboard" CssClass="form-control" OnSelectedIndexChanged="ddsscboard_SelectedIndexChanged" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Not Applicable</asp:ListItem>
<asp:ListItem>SSC</asp:ListItem>
<asp:ListItem>CBSC</asp:ListItem>
<asp:ListItem>ICSC</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>

Related

Align 2nd column textbox to 1st column textbox with label in Bootstrap

How do I align my 2nd column textbox to the first one with label in Bootstrap? Here's my current code:
<div class="form-group">
<div class="col-md-6">
<asp:Label ID="lblFullName" runat="server" Text="Full Name" AssociatedControlID="txtFirstName" CssClass="control-label"></asp:Label>
<asp:TextBox ID="txtFirstName" runat="server" CssClass="form-control" placeholder="First Name"></asp:TextBox>
</div>
<div class="col-md-6">
<asp:TextBox ID="txtLastName" runat="server" CssClass="form-control" placeholder="Last Name"></asp:TextBox>
</div>
</div>
You create two rows:
<div class="form-group container">
<div class="row">
<div class="col-md-6">
<asp:Label ID="lblFullName" runat="server" Text="Full Name" AssociatedControlID="txtFirstName" CssClass="control-label"></asp:Label>
</div>
<div class="col-md-6"/>
</div>
<div class="row">
<div class="col-md-6">
<asp:TextBox ID="txtFirstName" runat="server" CssClass="form-control" placeholder="First Name"></asp:TextBox>
</div>
<div class="col-md-6">
<asp:TextBox ID="txtLastName" runat="server" CssClass="form-control" placeholder="Last Name"></asp:TextBox>
</div>
</div>
</div>

Asp C# get control in repeat

I have this html/marckup code
<div class="col-md-12 pre-scrollable">
<asp:repeater runat="server" ID="rptDataInputs">
<itemtemplate>
<div class="row">
<div class="form-group">
<label class="col-md-2 control-label" for="textinput"><asp:Literal ID="Literal22" Text='<%#DataBinder.Eval(Container.DataItem, "ID") %>' runat="server" /></label>
<div class="col-md-6">
<asp:textbox ID="tb_value" MaxLength="10" runat="server" class="form-control" style="margin-bottom:10px;" Text='<%#DataBinder.Eval(Container.DataItem, "Value") %>'/>
</div>
<div class="col-md-2">
<asp:CheckBox Text="" runat="server" Checked='<%#DataBinder.Eval(Container.DataItem, "Insert").Equals("1") %>'/>
</div>
<div class="col-md-2">
<label runat="server" id="lbl_break"><input runat="server" id="break" type="radio" name="optradio"></label>
</div>
</div>
</div>
</itemtemplate>
</asp:repeater>
</div>
i need to get the value in the radio for each line.
How could i do this?

Asp:Button not firing in bootstrap Tab Panes

I have set a bootstrap tab pane, within this tab pane there is a form, on asp:Button press the code will not execute.
I know the code works as when not in the tab pane it works every time.
But its for a user control page and would be better to provide function within the tab panes.
This is for all buttons within the tab pane.
if one gets solved then the method to repair others is made!
Here is the HTML markup:
<div class="tab-content col-lg-10">
<div class="tab-pane active" id="pane1">
<%--Content goes in here, so tables, and whatever else--%>
<h3>My Bookings</h3>
<div class="container">
<asp:GridView runat="server" ID="dgBookingView" AutoGenerateColumns="False" DataSourceID="myBookings" CssClass="table table-striped table-bordered" UseAccessibleHeader="True">
<Columns>
<asp:BoundField DataField="BookingID" HeaderText="Booking #" InsertVisible="False" SortExpression="BookingID" />
<asp:BoundField DataField="FilmName" HeaderText="Movie" SortExpression="FilmName" />
<asp:BoundField DataField="Requirements" HeaderText="Requirements" SortExpression="Requirements" />
<asp:BoundField DataField="Showtime" HeaderText="Time" SortExpression="Showtime" DataFormatString="{0:t}" />
<asp:BoundField DataField="ShowDate" HeaderText="Date" SortExpression="ShowDate" DataFormatString="{0:d}" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="myBookings" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT Booking.BookingID, Booking.CustomerFK, Booking.AuditorumFK, Booking.Requirements, Film.FilmName, Showtime.Showtime, Showtime.ShowDate, Showtime.AuditoriumID, Customers.UserNameFK FROM (((((Booking INNER JOIN Seat ON Booking.BookingID = Seat.BookingFK) INNER JOIN Auditorium ON Seat.AuditoriumFK = Auditorium.AuditoriumID) INNER JOIN Showtime ON Auditorium.AuditoriumID = Showtime.AuditoriumID) INNER JOIN Film ON Showtime.FilmFK = Film.FilmID) INNER JOIN Customers ON Booking.CustomerFK = Customers.CustomerID)
WHERE([Customers.UserNameFK] = ? )">
<SelectParameters>
<asp:SessionParameter
Name="userNamePa"
SessionField="userName"
DefaultValue="userName" />
</SelectParameters>
</asp:SqlDataSource>
</div>
<div class="row">
<h3>Specify any Special Requirements</h3>
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">Booking #</label>
<div class="col-sm-6">
<asp:TextBox runat="server" CssClass="form-control" ID="txtBookingID"></asp:TextBox>
</div>
<div class="col-sm-4">
<h4>
<asp:RequiredFieldValidator ID="rqfUserNameValid" ControlToValidate="txtBookingID" runat="server"
ErrorMessage="Enter a Booking Number" CssClass="label label-danger">
</asp:RequiredFieldValidator>
</h4>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Extra Requirements</label>
<div class="col-sm-6">
<asp:TextBox ID="txtRequirements" class="form-control" Rows="5" runat="server"></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-6">
<asp:Button runat="server" CssClass="btn btn-default" Text="Make Change" ID="btnRequirements" OnClick="btnRequirements_OnClick" />
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="pane2" runat="server">
<%--Change User Password START--%>
<h3>Change Password</h3>
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">Current Password</label>
<div class="col-sm-6">
<asp:TextBox runat="server" CssClass="form-control" ID="txtCurrentPass" TextMode="Password"></asp:TextBox>
</div>
<div class="col-sm-4">
<h4>
<asp:RequiredFieldValidator runat="server" CssClass="label label-danger" ID="rqfCurrentPassword" ControlToValidate="txtCurrentPass"
ErrorMessage="Enter Current Password">
</asp:RequiredFieldValidator>
</h4>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">New Password</label>
<div class="col-sm-6">
<asp:TextBox runat="server" CssClass="form-control" TextMode="Password" ID="txtNewPassword"></asp:TextBox>
</div>
<div class="col-sm-4">
<h4>
<asp:RequiredFieldValidator runat="server" CssClass="label label-danger" ID="rqfNewPassword" ControlToValidate="txtNewPassword"
ErrorMessage="Required">
</asp:RequiredFieldValidator>
</h4>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Confirm Password</label>
<div class="col-sm-6">
<asp:TextBox runat="server" CssClass="form-control" TextMode="Password" ID="txtConfirmPassword"></asp:TextBox>
</div>
<div class="col-sm-4">
<h4>
<asp:RequiredFieldValidator runat="server" CssClass="label label-danger" ID="rqfConfirmPassword" ControlToValidate="txtConfirmPassword"
ErrorMessage="Required">
</asp:RequiredFieldValidator>
</h4>
<h4>
<asp:CompareValidator runat="server" ControlToValidate="txtConfirmPassword" ControlToCompare="txtNewPassword" ID="PassCompare" ErrorMessage="Confirm password must match password" CssClass="label label-danger"></asp:CompareValidator>
</h4>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-6">
<asp:Button runat="server" CssClass="btn btn-default" Text="Change Password" ID="btnPasswordChange" OnClick="btnChangePassword_OnClick"></asp:Button>
</div>
</div>
</div>
<div class="col-sm-4">
<h4>
<asp:Label runat="server" CssClass="label label-danger" ID="lblPassChange" Visible="False" Text=""></asp:Label>
</h4>
</div>
</div>
<%--Change User Password--%>
</div>
</div>
And the C# Code for button Event:
protected void btnChangePassword_OnClick(object sender, EventArgs eventArgs)
{
//Changes Password of current Logged in User
string oldPass = txtCurrentPass.Text;
string newPass = txtNewPassword.Text;
MembershipUser user = Membership.GetUser(User.Identity.Name);
if (txtCurrentPass.Text == txtNewPassword.Text)
{
lblPassChange.Visible = true;
lblPassChange.Text = "Old Password must not match New Password";
}
else
{
if (user != null && user.ChangePassword(oldPass, newPass))
{
lblPassChange.Visible = true;
lblPassChange.Text = "Password Changed Successfully";
lblPassChange.CssClass = "label label-success";
}
else
{
lblPassChange.Visible = true;
lblPassChange.Text = "Error, Please try again";
}
}
}
Where am i going wrong?
Any help would be appreciated

HTML (ASP.NET) div rendered inside previous div rather than after it

I have the following in an aspx file:
...
<div class="graybg">
<div id="clmn1">
<div class="title2">Pick Up From:</div>
<div id="pickup_options" class="selservice" runat="server">
<div class="boxes">
<asp:ImageButton class="box1" src="./box1.png" runat="server" OnClick="OnClickAddress" alt="Ground Address" />
<div class="boxtitle">Ground Address</div>
</div>
<div class="boxes">
<asp:ImageButton class="box1" src="./box2.png" runat="server" OnClick="OnClickAirport" alt="Airport" />
<div class="boxtitle">Airport</div>
</div>
</div>
<div id="pickup_airport" runat="server">
<div class="rows">
<div class="inputbtnholder">
<asp:TextBox class="input1" ID="TextBox1" placeholder="Enter Flight Number" runat="server"></asp:TextBox>
<div id="Div1_pkup" class="imgbtn searchbtn"></div>
</div>
</div>
<div class="rows">
<asp:TextBox class="input1 martop" ID="TextBox2" placeholder="Airport" runat="server" />
<div id="airport_search" class="imgbtn searchbtn" />
</div>
<div class="rows">
<div class="inputbtnholder">
<script type="text/javascript"> ...
<asp:TextBox ID="pickupdatetime" class="input1 martop" placeholder="Select Date and Time" runat="server"></asp:TextBox>
<div id="Div2_pkup" class="imgbtn datebtn"></div>
</div>
</div>
</div>
<div id="pickup_ground" runat="server">
<div class="inphld">
<asp:TextBox class="input1" ID="address" placeholder="Search for address" runat="server"></asp:TextBox>
<div id="searchbtn" class="imgbtn searchbtn"></div>
</div>
<div class="inphld">
<asp:TextBox class="input1 martop" ID="pickupdate" placeholder="Select Date and Time" runat="server"></asp:TextBox>
<div id="datebtn" class="imgbtn datebtn"></div>
</div>
</div>
</div>
</div>
<div class="selservice">
....
All my indentation matching inspections (manual and automatic) tell me that the div of class selservice in the last row is after the div of class graybg. When I publish and surf to the page in Chrome, the rendering is messed up. Inspection with the chrome developer tools shows that selservice follows clmn1 within graybg. If I remove the line defining "airport_search", the rendering is correct, and the developer tools show selservice following graybg, as it should.
Can anyone explain this?
Change from a self closing tag. I.e.
<div id="airport_search" class="imgbtn searchbtn" />
to
<div id="airport_search" class="imgbtn searchbtn"></div>

fill controls of web user control from parent page

i have two web user control in one the grid view is showing the result and the other contains the simply textboxes and the dropdowns that are basically created to edit that gridview items
the aspx.cs page code is
GridView gView = PlaceHolder2.Controls[0].FindControl("grvBranches") as GridView;
int index = gView.SelectedIndex;
GridViewRow grd = gView.Rows[index];
Label lbl = (Label)grd.FindControl("lblID");
int rowid = 0;
int.TryParse(lbl.ToString(), out rowid);
In rowid i contains the id of that item which is selected
now i want to fill all the following items in webusercontrol
<div class="col2_form1">
<div class="form1_bar1">
<div class="form1_txt1_div">
<asp:Label ID="lblBranchName" runat="server" Text="Branch Name">
</asp:Label>
</div>
<div class="form1_txtfield_div">
<asp:TextBox runat="server" ID="txtBranchName" class="form1_TxtField" />
</div>
<div class="form1_txt2_div">
<asp:RequiredFieldValidator ID="RFVBranchName" ErrorMessage="*" Display="Dynamic"
ValidationGroup="Save" ControlToValidate="txtBranchName" runat="server" />
<%-- <asp:Label Text="Error" ID="lblBranchNameError" runat="server" />--%>
</div>
</div>
<div class="form1_bar2">
<div class="form1_txt1_div">
<asp:Label Text=" Organization Name" ID="lblOrganizationName" runat="server" />
</div>
<div class="form1_txtfield_div">
<asp:DropDownList ID="ddlOrganization" CssClass="form1_TxtField" runat="server">
</asp:DropDownList>
</div>
<div class="form1_txt2_div">
<%--<asp:Label Text="Error" ID="lblOrganizationNameError" runat="server" />--%>
</div>
</div>
<div class=" form1_bar1">
<div class="form1_txt1_div ">
<asp:Label Text="Address Line1" ID="lblAddresLine1" runat="server" />
</div>
<div class=" form1_txtfield_div">
<asp:TextBox runat="server" ID="txtAddresLine1" CssClass="form1_TxtField" />
</div>
<div class="form1_txt2_div ">
<asp:RequiredFieldValidator ErrorMessage="*" Display="Dynamic" ValidationGroup="Save"
ControlToValidate="txtAddresLine1" runat="server" />
</div>
</div>
<div class=" form1_bar2">
<div class="form1_txt1_div ">
<asp:Label Text="Address Line2" ID="lblAddresLine2" runat="server" />
</div>
<div class="form1_txtfield_div ">
<asp:TextBox runat="server" ID="txtAddresLine2" CssClass="form1_TxtField" />
</div>
<div class="form1_txt2_div ">
</div>
</div>
<div class="form1_bar1 ">
<div class="form1_txt1_div">
<asp:Label Text="Country" ID="lblCountry" runat="server" />
</div>
<div class="form1_txtfield_div " style="float: left;">
<asp:DropDownList ID="ddlCountry" AutoPostBack="true" CssClass="form1_TxtField" runat="server"
OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
</asp:DropDownList>
</div>
<div class=" form1_txt2_div">
</div>
</div>
<div class=" form1_bar2">
<div class="form1_txt1_div ">
<asp:Label Text="State" ID="lblState" runat="server" />
</div>
<div class="form1_txtfield_div ">
<asp:DropDownList ID="ddlState" AutoPostBack="true" CssClass="form1_TxtField" runat="server"
OnSelectedIndexChanged="ddlState_SelectedIndexChanged">
</asp:DropDownList>
</div>
<div class="form1_txt2_div ">
</div>
</div>
<div class="form1_bar1 ">
<div class="form1_txt1_div ">
<asp:Label Text="City" ID="lblCity" runat="server" />
</div>
<div class="form1_txtfield_div ">
<asp:DropDownList runat="server" CssClass="form1_TxtField" ID="ddlCity">
</asp:DropDownList>
</div>
<div class="form1_txt2_div ">
</div>
</div>
<div class="form1_bar2 ">
<div class="form1_txt1_div ">
</div>
<div class="form1_txtfield_div">
<asp:Button Text="Save" Width="100px" runat="server" ID="btnSave" ValidationGroup="Save"
OnClick="btnSave_Click" />
</div>
<div class="form1_txt2_div">
<asp:Label Text="" ID="lblMsg" Visible="false" runat="server" />
</div>
</div>
i have a property on the webusercontrol as
public string ABC_DEF
{
set { txtABC.Text = value; }
get { return txtABC.Text; }
}
and on the parent page i.e on the aspx page i call it as
if (ViewState["controlname"] != null)
{
PlaceHolder pl = MainPanel.FindControl(ViewState["controlname"].ToString()) as PlaceHolder;
pl.Controls.RemoveAt(0);
}
Control uc = (Control) Page.LoadControl("~/usercontrols/control_forms/branch_aspx_form.ascx");
ViewState["path"] = "~/usercontrols/control_forms/branch_aspx_form.ascx";
ViewState["controlname"] = "PlaceHolder1";
PlaceHolder1.Controls.Add(uc);
branch_view[] branch_to_edit = EntityService.ServiceInstance.GetBranchByBranchID(row_id);
foreach (branch_view item in branch_to_edit)
{
usercontrols.control_forms.branch_aspx_form branch_control =
new usercontrols.control_forms.branch_aspx_form();
branch_control.ABC_DEF = " hello"; // Call property here
}
thanks
Gurbax
In your user control .ascx file create properties for each of the fields you need to be pulled onto the user control,
Then you can simply access them from the .aspx page by specifying the UserControlId.Property syntax like so:
public string Name
{
get { return txtName.Text; }
set { txtName.Text = value; }
}
public string Surname
{
get { return txtSurname.Text; }
set { txtSurname.Text = value; }
}
On the .aspx page the properties can be accessed like this:
protected void PopulateUserControl_Click(object sender, EventArgs e)
{
userControlName.Name = "Bob";
userControlName.Surname = "The Builder";
}

Categories