modalpopupextender always shown and targetcontrolid is not working - asp.net

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.

Related

RadioButtonList SelectedIndexChanged event not firing

i want event to fire when selection of radio button list change. but it fire when i click on another button. not on selected index changed.
please note i'm also using bootstrap. without bootstarp it is working
my code is as follow.
Source Code
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
RepeatDirection="Horizontal" BorderStyle="None" CellPadding="5"
CssClass="col-xs-pull-12">
<asp:ListItem Selected="True">All User</asp:ListItem>
<asp:ListItem > SpeciFic Users</asp:ListItem>
</asp:RadioButtonList>
Code behind
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("hi");
}
Also try displaying the list item to find out whether the event is firing or not.
Check out this link, it has a clear definition with an example...Click here
<link href="css/bootstrap-3.3.5.min.css" rel="stylesheet" />
<%--<script src="js/bootstrap-3.1.1.min.js"></script>--%>
2 things for me:
Removed script (unsure if versioning made the difference) the css file made no difference) duh
Needed a separate method to call ( i had nearly all postback events calling the same method ~ 13 controls) (also unsure if every radio control needs their own callback method or not)
.aspx
<div id="rdoSelectOptionsList" class="btn-group" data-toggle="buttons">
<asp:RadioButton ID="rdoShow" GroupName="rdoSelectOptions" runat="server" Checked="true" CssClass="btn btn-default" Text="Show all" />
<asp:RadioButton ID="rdoHide" GroupName="rdoSelectOptions" runat="server" CssClass="btn btn-default" Text="Hide all" />
<asp:Label ID="lblRdoSelectOptions" runat="server" CssClass="form-control-static"/>
</div>
script
$("#rdoSelectOptionsList :radio").each(function () {
if ($(this).is(':checked')) {
$(this).parent().addClass("active");
}
});

get info from one page and show it on other page

i m working on shopping cart site
i want to show complete information of a product contained in a div section. on an other page. i have may div that contained information.
goal is to get the info on a new page when user clicks some product's image.
Error:
Control 'MainContent_ImageButton1' of type 'ImageButton' must be placed inside a form tag with runat=server.
HTML:
<div id="physics" runat="server">
<h3>High School Physics</h3>
<%-- <img src="images/Book.jpg" /> --%>
<asp:ImageButton ID="ImageButton1"
src="images/Book.jpg" runat="server" onclick="ImageButton1_Click" />
<p> Book Description Goes Here
<br />
<asp:Label ID="Label1" runat="server" Text="Label">PKR 770/-</asp:Label>
<br />
<asp:TextBox ID="TextBox1" Text="1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Add" />
</p>
</div>
Code :
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
StringWriter sw = new StringWriter();
HtmlTextWriter w = new HtmlTextWriter(sw);
physics.RenderControl(w);
Session["mySessionVar"] = sw.GetStringBuilder().ToString();
Response.Redirect("ShowLarge.aspx", true);
}
HTML: where i want to show this info
<div id="ShowInLargeView" runat="server">
</div>
Code:
protected void Page_Load(object sender, EventArgs e)
{
ShowInLargeView.InnerHtml = (String)Session["mySessionVar"];
}
i want to show the complete info of Div in an other page. i m getting an error. this scenario is about shopping cart
i need help
please help.
The error you are getting is related to the fact that you are trying to add an event handler
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
In order to add an event handler to an element on your page it will need to be encapsulated in a 'form' with the runat="server" attribute. this will result in the click event of the ImageButton ending up in your code-behind.
so your aspx would become something like :
<form runat="server">
<div id="physics" runat="server">
<h3>High School Physics</h3>
<%-- <img src="images/Book.jpg" /> --%>
<asp:ImageButton ID="ImageButton1"
src="images/Book.jpg" runat="server" onclick="ImageButton1_Click" />
<p> Book Description Goes Here
<br />
<asp:Label ID="Label1" runat="server" Text="Label">PKR 770/-</asp:Label>
<br />
<asp:TextBox ID="TextBox1" Text="1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Add" />
</p>
</div>
</form>
In general it should suffice to encapsulate your entire page in a form tag, this way all events will be passed to your code-behind.

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();

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" />

Getting control that fired postback in page_init

I have a gridview that includes dynamically created dropdownlist. When changing the dropdown values and doing a mass update on the grid (btnUpdate.click), I have to create the controls in the page init so they will be available to the viewstate. However, I have several other buttons that also cause a postback and I don't want to create the controls in the page init, but rather later in the button click events.
How can I tell which control fired the postback while in page_init? __EVENTTARGET = "" and request.params("btnUpdate") is nothing
It is possible to determine which control caused a PostBack by looking at Request.Form["__EVENTTARGET"]. The problem with this is that button ids will not show unless you set their UseSubmitBehavior to false. Here's an example:
.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
switch (Request.Form["__EVENTTARGET"].ToString())
{
case "ddlOne":
break;
case "btnOne":
break;
case "btnTwo":
break;
}
}
}
.aspx
<form id="form1" runat="server">
<asp:DropDownList ID="ddlOne" AutoPostBack="true" runat="server">
<asp:ListItem Text="One" Value="One" />
<asp:ListItem Text="Two" Value="Two" />
</asp:DropDownList>
<asp:Button ID="btnOne" Text="One" UseSubmitBehavior="false" runat="server" />
<asp:Button ID="btnTwo" Text="Two" UseSubmitBehavior="false" runat="server" />
</form>

Resources