asp.net dropdown tool tip not shown when modal popup is opened - asp.net

I have a asp.net dropdown control to which tool tip has been added. It works fine on the mouse over. I also have a Modal Popup in that page. When I open and close the Modal Popup the tool tip in the drop are no more shown.
Below is my code.
<div class="col">
<div class="labelname required">
<asp:Label ID="lblsupplier" runat="server" Text="Supplier"></asp:Label>
</div>
<div class="labelvalue">
<asp:DropDownList ID="DdlSupplier" TabIndex="11" runat="server" AutoPostBack="true"
CausesValidation="false" OnSelectedIndexChanged="DdlSupplier_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="reqSupplier" runat="server" ControlToValidate="DdlSupplier"
ValidationGroup="SubmitGroupMain" InitialValue="0" ErrorMessage="Please Select Supplier Name"
SetFocusOnError="true" Display="None"></asp:RequiredFieldValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender7" runat="Server"
TargetControlID="reqSupplier" HighlightCssClass="validatorCalloutHighlight">
</ajaxToolkit:ValidatorCalloutExtender>
</div>
<asp:LinkButton runat="server" ID="lnkAddSupplier" CssClass="btnadd" ToolTip="New Supplier"
OnClick="lnkAddSupplier_Click"></asp:LinkButton>
<asp:Button runat="server" ID="popupshowAccount" Style="display: none" />
</div>
</div>
Code behind
foreach (ListItem item in DdlSupplier.Items)
{
item.Attributes.Add("title", item.Text);
}
DdlSupplier.Attributes.Add("onmouseover","this.title=this.options[this.selectedIndex].title");
Clicking on lnkAddSupplier opens up a popup. After closing the popup tool tip is not visible for the dropdown.
Please help on solving this issue.

Attributes won't be saved in Viewstate and that's why they will disappear across postbacks. Similar is the case with Custom Attributes.
That's why we have to use DropDownList Pre Render event to set attributes
protected void DropDownList1_PreRender(object sender, EventArgs e)
{
foreach (ListItem item in DropDownList1.Items)
item.Attributes.Add("title", "Something to test!!!!!!");
}

Related

Why does my gridview's edit\update not work after I add item to it at runtime

On my Page I have a textbox and a submit button which adds an item to my gridview which has edit/update functionality.All this is in an update panel.
I am binding my gridview with data from database using sqlreader. The edit/update option works fine when it bind it first time. but once I add an Item at runtime, the newly added item gets added to my gridview but edit update stops working. Also, not able to add new item after that.
Please find my sample code below
This is my HTML code:
-
<li>
<input type="radio" id="tabb" name="tabs11"/>
<label for="tabb">Family Name</label>
<div id="tab-content12" class="tab-content animated fadeIn" style="background-color:white; padding:10px;" >
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:Button ID="BtnAddFamilyName" runat="server" Text="Add" CssClass="buttons" OnClick="BtnAddFamilyName_Click" /><br />
<asp:Label ID="Label1" runat="server" Text="Enter Family Name"></asp:Label>
<asp:TextBox ID="FamilyNameTextBox" runat="server" CssClass="inputs" placeholder="Enter Family Name"></asp:TextBox>
<asp:Button ID="BtnSubmitFamilyName" runat="server" Text="Submit" OnClick="BtnSubmitFamilyName_Click" CssClass="inputs"/><br /><br />
<asp:GridView ID="gdvEDitFamilyName" runat="server" OnRowEditing="gdvEDitFamilyName_RowEditing" OnRowCancelingEdit="gdvEDitFamilyName_RowCancelingEdit" OnRowUpdating="gdvEDitFamilyName_RowUpdating" AutoGenerateEditButton="true" DataKeyNames="FamilyId" CssClass="grid" RowStyle-CssClass="rows">
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</li>
2: My code behind for binding the gridview:
SqlDataReader reader = DataExecuter.ReadMultipleRows("spBindHIGridview",
CommandType.StoredProcedure);
reader.NextResult();
gdvEDitFamilyName.DataSource = reader;
gdvEDitFamilyName.DataBind();
3:My code behind for adding the item to the grid:
protected void BtnSubmitFamilyName_Click(object sender, EventArgs e)
{
if (FamilyNameTextBox.Text.Equals(""))
{
ScriptManager.RegisterClientScriptBlock(this,
this.GetType(), "alertMessage", "alert('Please enter a
value')", true);
}
else
{
DataExecuter.ExecuteCommand("spInsertFamilyName", new[,] { {
"#FamilyName", FamilyNameTextBox.Text } },
CommandType.StoredProcedure);
this.BindDdl();
this.BindGrid();
ScriptManager.RegisterClientScriptBlock(this,
this.GetType(), "alertMessage", "alert('Record Inserted
Successfully')", true);
}
}
After the 3rd step i can't add a new item or edit/update the gridview

Handle user control dropdownlist selected index change event in aspx page

I have create the user control and add the same in aspx code behind. I want to handle the selected index change event for dropdownlist in aspx page. Kindly help me to do this.
<div class="row">
<div class="col-lg-2">
<asp:Label ID="lbl_parent" runat="server" Text="Parent Node" CssClass="control-label"></asp:Label>
</div>
<div class="col-lg-6">
<asp:DropDownList ID="ddl_parent" runat="server" CssClass="form-control" AutoPostBack="true">
</asp:DropDownList>
</div>
</div>
phContactDetails.Controls.Add(LoadControl("~/UserControl/WUC_DisLabelControl.ascx"));
foreach (var control in phContactDetails.Controls)
{
var usercontrol = control as WUC_DisLabelControl;
DropDownList ddl_parenrt = ((DropDownList)usercontrol.FindControl("ddl_parent"));
ddl_parenrt.SelectedIndexChanged += new EventHandler(ddlparent_SelectedIndexChanged);
}
protected void ddlparent_SelectedIndexChanged(object sender, EventArgs e)
{
throw new NotImplementedException(); //Not Firing
}
You have not added SelectedIndexChanged event on dropdown.
Add SelectedIndexChanged="ddlparent_SelectedIndexChanged" on dropdown.
<asp:DropDownList ID="ddl_parent" runat="server" CssClass="form-control" AutoPostBack="true" OnSelectedIndexChanged="ddlparent_SelectedIndexChanged">
</asp:DropDownList>

modalpopupextender always shown and targetcontrolid is not working

I have a repeater and it has a column of linkbuttons in it. I want to add those linkbuttons to targetcontrolid but it failed because they are in the repeater. So i create an additional invisible button like this :
<asp:Button ID="btnFakePopUp" runat="server" Text="" visible="false"
onclick="btnFakePopUp_Click"/>
And in i tried to link the linkbutton to the invisible button in this code :
protected void lbtnPosition_Click(object sender, EventArgs e) {
btnFakePopUp_Click(sender, e);
}
protected void btnFakePopUp_Click(object sender, EventArgs e)
{
popupJob.Show();
}
And this is my modalpopupextender code (my prefix is asp: so dont get confuse) :
<asp:ModalPopupExtender ID="popupJob" runat="server" PopupControlID="panelPopup" CancelControlID="popupClose" TargetControlID="btnFakePopUp"
Drag="true" PopupDragHandleControlID="panelPopup">
</asp:ModalPopupExtender>
<asp:Panel ID="panelPopup" runat="server" BackColor="#ebf0ff" Width="300px">
<div>
test<br />
<asp:Button ID="btnSave" runat="server" Text="Save" />
<asp:Button ID="btnApply" runat="server" Text="Apply" />
<input id="popupClose" type="button" value="Close" />
</div>
</asp:Panel>
The problems are :
1. The panelpopup is always shown...(it should be hidden, and only be shown when the user click the link button)
2. Nothing happened when i tried to click the link button (the panelpopup should be shown)
Thank you :D
For a btnFakePopup invisible you could set the display:none with CSS
example:
<asp:ImageButton ID="btnFakePopUp" runat="server" style="display: none"></asp:ImageButton>
I don't understand why, but setting btnFakePopUp visibility to true corrected the problem. Now my modalpopupextender is running smoothly.

activate ModalPopupExtender witheout giving it TargetControlID in asp.net

how can i activate a ModalPopupExtender,
whiteout giving the TargetControlID a button id in the aspx page (i dont know wiche button will activate the ModalPopupExtender i have a multiple buttons on my page)
thanks
you must have one TargetControlID but you can hide it and activate the pop up with a different button:
<div style="display:none;">
<asp:LinkButton runat="server" ID="lbPrivacy" Text="PRIVACY"/>
</div>
<asp:ModalPopupExtender ID="MpePrivacy" runat="server" TargetControlID="lbPrivacy"
<asp:LinkButton runat="server" ID="lbPrivacy2" Font-Underline="true"
CausesValidation="false" OnClick="btMpePrivacy_Click">Privacy</asp:LinkButton>
protected void btMpePrivacy_Click(object sender, EventArgs e)
{
AjaxControlToolkit.ModalPopupExtender modalPop = ((AjaxControlToolkit.ModalPopupExtender)(this.Master.FindControl("ContentPlaceHolder1").FindControl("MpePrivacy")));
modalPop.Show();
}
Tip: you can use Hidden field as a TargetControlID:
<asp:HiddenField ID="btnTrigger" runat="server" />
and as for showing the popup, in each button onclick event:
(IdOfModalPopupExtender).show();
ModalPopupExtender_xyz.Show();

Shading every other row in a VB.net Listview?

I have been Googling this for about a day now, and every post I find is too old and Visual Studio doesn't recognize some pieces of code that people have posted. I have a dynamically populated Listview. I would really like every other line to be shaded for readability purposes, and just can't figure it out.
Everything I try to do messes with the Modal PopupExtender that I have inside of the Listview. It trys to shade the lines inside the PopUpBox too. This is one of the Listviews that I would like shaded.
<!-- Descriptions -->
<asp:TabPanel ID="tab2" runat="server" HeaderText="Descriptions">
<HeaderTemplate>Descriptions</HeaderTemplate>
<ContentTemplate>
<ul class="info">
<asp:ListView ID="lvDescriptions" runat="server" DataSourceID="dsMarketingDescriptions" DataKeyNames="MarketingID">
<ItemTemplate>
<li>
<asp:LinkButton ID="ViewDescriptionButton" runat="server"><%#Eval("MarketingTitle")%></asp:LinkButton>
<asp:Panel ID="ViewDescriptionPanel" runat="server" CssClass="DescModalPopup"> <div class="PopupHeader" id="PopupHeader">View Description
<asp:ImageButton ID="CancelDescriptionButton" runat="server" ImageUrl="../../images/exit.png" AlternateText="" Style="float:right;"/>
</div>
<asp:Label ID="Description" runat="server" style="padding:5px;"><%# Eval("MarketingData") %></asp:Label>
</asp:Panel>
<asp:ModalPopupExtender ID="ViewDescriptionModal" runat="server" BackgroundCssClass="modalBackground" DropShadow="false" DynamicServicePath="" Enabled="true" PopupControlID="ViewDescriptionPanel" TargetControlID="ViewDescriptionButton" CancelControlID="CancelDescriptionButton"></asp:ModalPopupExtender>
</li>
</ItemTemplate>
</asp:ListView>
</ul>
</ContentTemplate>
</asp:TabPanel>
Try using the AlternatingItemTemplate to specify a different background color for alternating items.
Are you trying to do something like this with the ModalPopupExtender?:
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Panel pnl = e.Item.FindControl("Panel1") as Panel;
if (pnl != null)
{
pnl.BackColor = ListView1.Items.IndexOf(e.Item) % 2 == 1 ? Color.PeachPuff : Color.White;
}
}

Resources