I have a usercontrol as a header on a page. The usercontrol has sign up button which opens a modalpopupextender. The popup open code on sign up link is below:
protected void lnkSignUp_Click(object sender, EventArgs e)
{
mp1.Show();
}
Now I am able to successfully use this usercontrol in my page. The problem is in my page there are other links apart from header which will provide sign up facility. Now I want to use the same signup popup of usercontrol to be opened by clicking on page sign up links. What should I do on page link click. I have tried the below code from page but myMpeModal returns null:
ucHeaderJobseeker uc1 = new ucHeaderJobseeker();
var myMpeModal = (AjaxControlToolkit.ModalPopupExtender)uc1.FindControl("mpeModal");
myMpeModal.Show();
Try doing something like this:
Your Front End (.aspx Page):
<uc1:WebUserControl runat="server" ID="myUserControl" />
Your UserControl Should look like this:
<ajax:ModalPopupExtender ID="mpeModal" runat="server" BackgroundCssClass="modalBackground"
PopupControlID="pnlShowMe" TargetControlID="btnClickMe" CancelControlID="btnClose">
</ajax:ModalPopupExtender>
<asp:Button ID="btnClickMe" runat="server" Text="Click Me" OnClick="btnClickMe_Click" />
<asp:Panel ID="pnlShowMe" runat="server" CssClass="ModalPanel">
</asp:Panel>
Your Code Behind (.aspx.cs):
var myMpeModal = (AjaxControlToolkit.ModalPopupExtender)myUserControl.FindControl("mpeModal");
myMpeModal.Show();
Here in the above code, "myUserControl" is your user control, "mpeModal" is your ModalPopupExtender id.
Use the above code where ever you want in your page to show the popup.
Related
I started to build a website using Umbraco and I noticed that button click events (and probably other events) are not working.
I created simplest usercontrol with one button, added it to a page, When I debug it the Page_Load is called (breakpoint being hit), but not button click.
The code is very standard, but here it is:
.aspx file
<%# Control Language="C#" AutoEventWireup="true" CodeFile="TestControl.ascx.cs" Inherits="usercontrols_TestControl" %>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
and code behind:
protected void Button1_Click(object sender, EventArgs e) {
Label1.Text = "Button clicked!";
}
Where can be the problem?
Make sure you are wrapping your body with <form runat="server">...</form> tags, the user control/macro should be inside the form tags. Also ensure that you are adding the user control correctly. To help you out with this, here are a few resources:
A demo by Niels Hartvig. (Niels is using a current Umbraco version.)
Tim Geyssens' screencast. (Tim is using an older version of Umbraco in the screencast (not 4.7.*), but there isn't much difference.)
Step-by-step instructions by Skiltz.
I have a question regarding passing Session Variables to a text-box in an Update Panel (which is displayed in a Modal PopUp).
This is the code I have so far:
ASPX CODE:
<asp:TemplateField HeaderText="Link">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Text="Link" runat="server" OnClick="LinkButton1_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="panel_Load">
<ContentTemplate>
<asp:Button ID="OKButton" runat="server" Text="Close" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:ModalPopupExtender ID="mpe" runat="server" TargetControlID="ClientButton" PopupControlID="UpdatePanel1" OkControlID="OKButton">
</asp:ModalPopupExtender>
<asp:Button ID="ClientButton" runat="server" Text="Launch Modal Popup (Client)" style="display:none;" />
CODE BEHIND (C#):
protected void LinkButton1_Click(object sender, EventArgs e)
{
GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
Label lbl_nme = (Label)clickedRow.FindControl("lbl_name");
String string_nme = lbl_nme.Text.ToString();
Session["Name"] = string_nme;
mpe.Show();
}
protected void panel_Load(object sender, EventArgs e)
{
Label1.Text = (string)(Session["Name"]);
}
So basically I have a GridView with name, address etc… When the user clicks on a link in a row, then the value for the name field of that row is saved as a session variable. Then a Modal PopUp is displayed. The Modal PopUp should then show the Name which was saved as a Session variable.
The code sort of works. What I’m experiencing is that when I click a row, the Label1.Text in the Modal PopUp is empty. So if I close the PopUp then click another link in another row, the PopUp then displays the Name of the row that was clicked previously.
In other words.. If row 1 has Name “Kevin” and row 2 has Name “Nathaniel”, and I click a link to open the Modal PopUp of row 1, I would expect the PopUp to display “Kevin”. But it doesn’t. The first time I click a link after rebuilding the application, nothing is displayed. But say I click row 2 after clicking row1, then the Modal PopUp displays the value of the row I clicked before, i.e. “Kevin” when I expect it to be “Nathaniel”.
I hope I didn’t confuse anyone. I’m a newbie and I’m just getting into this stuff, so I’d appreciate it if someone could help me out, preferably with examples of code etc.
Thank you. Much appreciated.
The "Load" event (panel_Load) occurs before the "Click" event (LinkButton1_Click) so it only sees the previous value.
The quick fix is to set the label in the "Click" event as well. Unless ViewState is enabled for the label (ick!) the label may have to be [re]set in the "Load" as well, depending upon when/how updates occur.
See ASP.NET Page Life Cycle Overview and ASP.NET Application and Page Life Cycle: Page Events.
Happy coding.
I have an .ascx control in my searchresults.aspx page:
<asp:LinkButton id="LinkButton1"
Text="Click Me"
Font-Names="Verdana"
Font-Size="14pt" PostBackUrl="~/searchresults.aspx?type=topics"
runat="server"/>
But when I click on it, it does the postback but the type=topics doesn't appear to be sent. Any suggestions?
Try out HyperLink to navigate to an other page:
<asp:HyperLink NavigateUrl="~/searchresults.aspx?type=topics" />
From MSDN:
HyperLink
A control that displays a link to another Web page.
On LinkButton class page:
If you want to link to another Web page when the control is clicked,
consider using the HyperLink control.
EDIT: Answer to comments
Remove PostBackUrl from LinkButton
Add <asp:LinkButton OnClick="OnTopicsTypesEnabled" ... />
In code behind (searchresults.aspx.cs)
protected void OnTopicsTypesEnabled(object sender, EventArgs args)
{
// handle this particular case
}
I believe your code will perform an POST, whereas you need a GET to transfer your variables through QueryString.
I have a master page and have included a search text box.
User is on default.aspx
user enters a search value in the search text box, which is part of master page.
Via javascript the form, in MP, is submitted to my search functionality page, search.aspx and the code behind search.aspx.cs obtains the form post and gets the data.
Search.aspx has a bare bone table to display the results.
I have a breakpoint in search.aspx.cs and am able to see the raw results returned from DB. However after all databinding has occured, the user is not directed from default.aspx to search.aspx
Don't use any javascript to submit the form, just set the PostBackUrl property of your search button to Search.aspx:
<asp:TextBox ID="TxtSearch" runat="server" />
<asp:LinkButton
ID="BtnSearch"
runat="server"
PostBackUrl="Search.aspx"
Text="Search" />
And in the Page_Load of Search.aspx read the posted value:
protected void Page_Load(object sender, EventArgs e)
{
string searchText = Request["TxtSearch"];
}
I am trying to get a modal popup to work, it needs to be triggered in the Code behind.
<asp:Button ID="btnModalPopUp" runat="server" Text="Button" Style="display: none" />
<asp:Panel ID="pnlModalPopup" runat="server" CssClass="modalPopup" Style="display: none"
Width="233px">
<div id="Div1" runat="server" cssclass="title">
Modal text here.
<asp:TextBox ID="txtEditComments" runat="server"></asp:TextBox>
</div>
</asp:Panel>
<cc1:ModalPopupExtender ID="modalMessage" runat="server" TargetControlID="btnModalPopUp"
PopupControlID="pnlModalPopup" BackgroundCssClass="modalBackground" DropShadow="true"/>
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
modalMessage.Show();
}
Even though it hits the "modalMessage.Show();" code it doesn't show the modal panel.
Two solutions:
The first solution:
Remove Style="display:none" from the pnlModalPopup.
The first solution is will cause the popup to "flash" on the screen when the page first loads, and then quickly disappear.
The second solution:
protected void Page_Load(object sender, EventArgs e)
{
pnlModalPopup.Style["display"] = "block";
modalMessage.Show();
}
Recommendation:
I would recommend using the second solution, that way the modal popup doesn't flicker and then disappear.
Edit: I just tested your code:
I just tested your code in a simple page that contained only the code that you provided...It worked like expected.
Check the following:
Is your modal popup is defined in an UpdatePanel that is conditionally updated?
Check to make sure that the modal popup isn't defined in a Panel that has it's visibility set to false.
If that doesn't work, then check if the modal popup is actually in the source code of the rendered web page.
Listen to Chris's comment as it is needed:
display:none is cosmetically needed,
otherwise the popup will display when
the page is loading, then will quickly
disappear while the ModalPopupExtender
kicks in and hides it.
We had to make ours show like this:
pnlModalPopup.Visible = true;
modalMessage.Show();