activate ModalPopupExtender witheout giving it TargetControlID in asp.net - 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();

Related

change from hyperlink to link btn

Had to change from asp:hyperlink to asp:linkButton, can no longer use navigateUrl in link button...any suggestions?
<asp:LinkButton ID="InvoiceLink" runat="server" NavigateUrl="~/Invoices/List.aspx">
<asp:Label id="labelBindfromHomeToInvoice" runat="server" Text="<%# Bind('Site_Name') %>"/>
</asp:LinkButton>
LinkButton doesn't work that way. LinkButton is more like a Button with a Hyperlink appeareance.
So you can handle the OnClick Event.
<asp:LinkButton ID="InvoiceLink" runat="server" OnClick="InvoiceLink_Click">
<asp:Label id="labelBindfromHomeToInvoice" runat="server" Text="<%# Bind('Site_Name') %>"/>
</asp:LinkButton>
In the CodeBehind
protected void InvoiceLink_Click(object sender, EventArgs e)
{
Response.Redirect("~/Invoices/List.aspx");
}
EDITED
I will improve this answer. The main difference between HyperLink and LinkButton is that HyperLink will not PostBack, it just simply request the NavigateURL to the server. The LinkButton is just a normal Button. This means that it will PostBack the server, with all the advantages and disadvantages to doing this (sending ViewState for example, update the controls, etc)
If you need just to redirect to another page, probably the best choice it will be HyperLink
LinkButton uses PostBackUrl, because you "post" the data to another url.
On a link button you use the PostBackUrl
<asp:LinkButton ID="InvoiceLink" runat="server"
PostBackUrl="~/Invoices/List.aspx">

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.

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

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

How to set the target control id of ajax modelpop up extender to a run time button created id?

I am creating a button at run time and on it's click i want to open a ajax model pop up.
But i am unable to set model pop up's target control id to this run time created button id.
Could some body suggest me how to achieve this? or any alternate way exist?
My code is as following.
This is how i am creaing a run time button.
protected void grdSurveyMaster_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridFooterItem)
{
GridFooterItem footerItem = (GridFooterItem)e.Item;
// RadScriptManager1.RegisterAsyncPostBackControl(btn);
Button btn = new Button();
btn.Text = "Take a new survey";
btn.CommandName = "newAssess";
btn.Click += new System.EventHandler(grdMasterbtnClick);
footerItem.Cells[2].Controls.Add(btn);
//ModalPopupExtender1.TargetControlID = "btn";// Convert.ToString(Page.FindControl(Convert.ToString(btn.ClientID)));
}
}
And following is my HTMl
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<cc1:ModalPopupExtender CancelControlID="btnCancel" PopupControlID="modelPopUp" ID="ModalPopupExtender1"
runat="server" TargetControlID="btnDefault">
</cc1:ModalPopupExtender>
<asp:Button ID="btnDefault" runat="server" Visible="false" />
<asp:Panel ID="modelPopUp" runat="server" Visible="false" BackColor="AliceBlue">
<p>
These items will be permanently deleted and cannot be recovered. Are you sure?
</p>
<asp:Button ID="btnOk" Text="OK" runat="server" />
<asp:Button ID="btnCancel" Text="Cancel" runat="server" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Well you're doing right setting the Popup's TargetControl an invisible unused button. Now the best way to show/hide your popup is from Javascript. For this you have to set the behaviorid="someString" of your ModalPopupExtender and create a javascript function like this:
function ShowModalPopup(behaviourId) {
$find(behaviourId).show();
}
Then you can assign the javascript function to a button:
btn.OnClientClick = String.Format("ShowModalPopup('{0}')",
ModalPopupExtender1.behaviorid);

How to close Modal popup Extender from Server side

How to close Modal Popup Extender from server side code on click on close link inside the popup?
there is a property in extender for closing popup " CancelControlID" give button id in it and popup will close,if you want to close popup from server side mean from code behind then there is extender property hide(),in button code behind body write id of popup and enter "." after that you get all properties of popup in those property you get hide property.use it hopefully you will get the solution
example
private void btnSubmit_Click(object sender, EventArgs e)
{
modelpopupextender.hide();
}
Answering this question might not be useful to the person who posted it but it might be useful to others.
The following needs to be done to close the modal popup from server side.
Instead of giving the close button id to "CancelControlID" of the modalpopupextender, create a dummy hiddenfield and give this id to "CancelControlID" of the modalpopupextender.
for example
<pre>
<asp:HiddenField ID="hidForModel" runat="server" />;
/*Are you sure you want to know the answer? */
<asp:Button ID="btnYes" runat="server" Text="Yes!" onclick="btnYes_Click" />;
<br />;
<asp:Panel ID="pnlModal" runat="server" CssClass="modalPopup" Style="display: none;">
<asp:Panel ID="pnlControls" runat="server" CssClass="insideModalPopup></asp:Panel>
<br />
<asp:Button ID="btnClose" runat="server" Text="Close" onclick="btnClose_Click" />
</asp:Panel>
<cc1:ModalPopupExtender TargetControlID="hidForModel" ID="pnlModal_ModalPopupExtender"
runat="server" DynamicServicePath="" Enabled="True" BackgroundCssClass="modalBackground"
PopupControlID="pnlModal" CancelControlID="hidForModel" DropShadow="true">
</cc1:ModalPopupExtender>
</pre>
Here i have given both TargetControlID and CancelControlID as hidForModel as I want to show as well as hide the modal popup from code-behind.
In Code-Behind
<pre>
protected void btnYes_Click(object sender, EventArgs e)
{
pnlModal_ModalPopupExtender.Show();
TextBox txt = new TextBox();
txt.Text = "aaa";
pnlControls.Controls.Add(txt);
}
protected void btnClose_Click(object sender, EventArgs e)
{
pnlModal_ModalPopupExtender.Hide();
}
</pre>
Here I have made the modal popup seen and added a textbox from code-behind on click of yes button and hidden the modal popup on click of Close button.
You can use CancelControlID attribute to close the Popup box.
<asp:ModalPopupExtender ID="mpe_login" runat="server"
TargetControlID="btn_login_popup" PopupControlID="panel_login"
BackgroundCssClass="LoginBackground1"
CancelControlID="btn_Cancel" />

Resources