Hi i have created one User control which is a Popup , It is absolutely working fine , But when i click on other buttons which is other than close button it is getting closed..
Here is my code,
<ajax:ModalPopupExtender ID="ModalPopupContextInfo" runat="server"
TargetControlID="btnShowEditContextPopup" PopupControlID="pnlpopupContextInfo"
CancelControlID="imgClose" BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
< asp:Panel ID="pnlpopupContextInfo" DefaultButton="imgbtnUpdate" runat="server" BackColor="White" Height="360px" Width="400px" Style="display: none" >
<asp:ImageButton ID="imgClose" runat="server" ImageUrl="~/image_repository/cancelButton.png" ToolTip="Close" />
..................
// Code for Labels and text boxes..
<asp:ImageButton ID="imgbtnCancel" runat="server" CausesValidation="false" TabIndex="8" ImageUrl="~/image_repository/cancel.png" />
<asp:ImageButton ID="imgbtnUpdate" runat="server" CausesValidation="false" TabIndex="8" ImageUrl="~/image_repository/UpdateVoyage.png" />
</asp:Panel>
Here when i click on Update or Cancel Button also the popup is getting closed..
how to respond the user control's button(Update here) click event from the parent web form (aspx page)
Can anyone help
Because you didn't put action. You should add onclick="Cancel_Click1" for example. And add the action in the server side.
Related
I am using the below code in ASP.NET to hide action buttons for simple users who can see only data but can't change it;
<asp:LoginView ViewStateMode="Disabled" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="HRAdmin">
<ContentTemplate>
<asp:Button ID="BtnAddnew" CssClass="bluebutton" title="Click to Add New Employee" runat="server" Text="Add New" OnClick="BtnAddnew_Click" />
<asp:Button ID="BtnSaveNew" CssClass="bluebutton" title="Click to Save New Record" runat="server" Text="Save New" Visible="false" OnClick="BtnSaveNew_Click" />
<asp:Button ID="BtnUpdate" CssClass="bluebutton" title="Click to Update Record" runat="server" Text="Update" OnClick="BtnUpdate_Click" />
<asp:Button ID="BtnSaveUpdate" CssClass="bluebutton" title="Click to Save Record" runat="server" Text="Save Update" Visible="false" OnClick="BtnSaveUpdate_Click" />
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
But when I load page or build project, then I get errors:
The name 'BtnAddnew' does not exist in the current context.
The name 'BtnSaveNew' does not exist in the current context.
The name 'BtnUpdate' does not exist in the current context.
The name 'BtnSaveUpdate' does not exist in the current context.
It means in the C# code it is not loading OnClick event of these buttons. How can I fix this problem?
This suggests that you don't in code behind
have the button click events.
Try removing the this part of each button:
So, change:
<asp:Button ID="BtnAddnew" CssClass="bluebutton"
title="Click to Add New Employee" runat="server"
Text="Add New" OnClick="BtnAddnew_Click" />
to:
<asp:Button ID="BtnAddnew" CssClass="bluebutton"
title="Click to Add New Employee" runat="server"
Text="Add New" />
Now, do a build-rebuild Solution
If you want to add a click event to each button, then in markup, type on OnClick=, and THEN let intel-sense suggest to you to create new event (a click event)
eg this:
It will seem like nothing occurred, but if you flip over to code behind, then the button click event should now exist.
In fact, before you try any of above, exit VS. Re-load. Do a bio;d ->rebuild solution. Then try the page - it it still don't work, then you need to do above.
you should check you aspx page cs refrence class.
<%# Page Title="" Language="C#" MasterPageFile="~/Test/Test/Test.master" AutoEventWireup="true" CodeFile="Test_Update.aspx.cs" Inherits="ProjectName_FolderName_Test_Update" %>
This is because I am using <asp:LoginView and buttons was inside it.That's why you may use below code:
Button BtnAddnew = ((Button)(this.LVButton.FindControl("BtnAddnew")));
Button BtnSaveNew = ((Button)(this.LVButton.FindControl("BtnSaveNew")));
Button BtnUpdate = ((Button)(this.LVButton.FindControl("BtnUpdate")));
Button BtnSaveUpdate = ((Button)(this.LVButton.FindControl("BtnSaveUpdate")));
Inside Grid View Image Button is not firing using an ASP.NET Web form. If I will use ASP Button, then working Button and easy adding.
Below is my design Code of grid view Button.
<FooterTemplate>
<asp:ImageButton ID="imgbtnAdd" runat="server" CommandName="AddNew" ImageUrl="~/Imgs/grid_add.png" ToolTip="click here to add" CausesValidation="true" ValidationGroup="Team_involved_directly" />
<%-- <asp:Button ID="Button1" runat="server" Text="Add" CommandName="AddNew" CausesValidation="true" ValidationGroup="Team_involved_directly" ToolTip="click here to add" />--%>
</FooterTemplate>
If I will use above commented button then working fine, but Image Button only giving Issue. And I also used !Page.IsPostBackin my page load.
Have you tried 'OnClick' method for button tag?
Code in aspx page
<asp:LoginView ID="loginView1" runat="server" EnableViewState="false">
<LoggedInTemplate>
<asp:Button ID="btnWatchlist" runat="server" Text="+ Watchlist" />
<asp:Button ID="btnPM" runat="server" Text="PM" />
<asp:Button ID="btnEdit" runat="server" Text="Edit" />
<asp:Button ID="btnReport" runat="server" Text="Report" />
</LoggedInTemplate>
</asp:LoginView>
Code in aspx.cs(Codebehind) to acccess the button id's
Button watchList = (Button)loginView1.FindControl("btnWatchlist");
Button pm = (Button)loginView1.FindControl("btnPM");
Button report = (Button)loginView1.FindControl("btnReport");
Button edit = (Button)loginView1.FindControl("btnEdit");
watchList,pm,report,edit is getting null values.Any mistake in my code?
Thanks in Advance..
Maybe stupid question, but are you signed in to your site? When testing I noted that the controls are only visible when signed in, so using FindControl in Page_Load would not find the controls unless I was signed in.
I am trying to create this webpage that shows a database with a "Master-Detail" type view. To do this I am following this tutorial http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html.
The only difference is that I am not using ObjectDataSource, instead I am just using my SQL - DataBase.
Here's the problem: When I click on the link to show the modalPopup, the BackgroundCssClass is not being applied, and the popup just shows up in the corner of the screen without changing the background and opacity. Anyone know whats going on?
Here's the code:
CSS
<style type="text/css">
TR.updated TD
{
background-color:yellow;
}
.modalBackground
{
background-color:Gray;
filter:alpha(opacity=70);
opacity:0.7;
}
</style>
Modalpopup part (right above this is the gridview that shows the "Master" section of the Database, this works fine so I didn't include it.
<asp:UpdatePanel ID="updPnlReservationDetail" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button id="btnShowPopup" runat="server" style="display:none" />
<ajaxToolKit:ModalPopupExtender ID="mdlPopup" runat="server"
TargetControlID="btnShowPopup" PopupControlID="pnlPopup"
CancelControlID="btnClose"
BackgroundCssClass="modalBackground" />
<asp:DetailsView ID="dvReservationDetail" runat="server" DataSourceID="mainTable" CssClass="detailgrid"
GridLines="None" DefaultMode="Edit" AutoGenerateRows="false" Visible="false" Width="100%">
<Fields>
<asp:BoundField HeaderText="LabName" DataField="labName" ReadOnly="true" />
<asp:TemplateField HeaderText="Email">
<EditItemTemplate>
<asp:TextBox ID="txtEmail" runat="server" Text="Hello" />
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<div class="footer">
<asp:LinkButton ID="btnSave" runat="server"
Text="Save" OnClick="BtnSave_Click" CausesValidation="true"
/>
<asp:LinkButton ID="btnClose" runat="server"
Text="Close" CausesValidation="false"
/>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
maybe you are using <asp:ScriptManager runat="server" /> instead of <ajaxToolKit:ToolkitScriptManager runat="server" />
here's a little example of "normal" usage, just in case
<asp:Button ID="btnShow_ClientSide" runat="server"
Text="show client side" OnClientClick="return false" />
<asp:Button ID="btnShow_ServerSide" runat="server"
Text="show server side" OnClick="btnShow_ServerSide_Click" />
<ajaxToolKit:ModalPopupExtender ID="mdlPopup" runat="server"
TargetControlID="btnShow_ClientSide"
PopupControlID="pnlPopup" CancelControlID="btnHide_ClientSide"
BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlPopup" runat="server"
BackColor="White" BorderColor="Black">
<asp:Button ID="btnHide_ClientSide" runat="server"
Text="hide client side" OnClientClick="return false" />
<asp:Button ID="btnHide_ServerSide" runat="server"
Text="hide server side" OnClick="btnHide_ServerSide_Click" />
</asp:Panel>
and in the code behind
protected void btnShow_ServerSide_Click(object sender, EventArgs e)
{
mdlPopup.Show();
}
protected void btnHide_ServerSide_Click(object sender, EventArgs e)
{
mdlPopup.Hide();
}
I had a completely different cause of this problem, and here's the solution, which I found on this very helpful walk-through page.
BackgroundCssClass: The name of the CSS class which needs to be applied to the background of the popup. One thing to note here is that if you don’t provide a CSS class then the modal popup will not function like a modal dialog i.e. One will be able to interact with the controls in the back of the popup control, so its imperative to provide a valid CSS class name value to the BackgroundCssClass property. In the above e.g. we have defined a CSS class called “backgroundColor” in the header section of the aspx page. Please note in the CSS class definition we have applied “filter” property to make the background transparent.
I had made a typo in the .css file, which prevented reading the background style. As soon as the CSS was working, the popup became modal and had its proper background.
I want to show a modal popup when a user click on an asp button. The user must select an option of a panel. The value of the option selected must be saved to an input hidden and then the asp.net button must do a PostBack.
Can I do that?
Thank you!
It is possible for a ModalPopupExtender to be displayed using a postback. You'll need an invisible target control. The extender is attached to this hidden control.
<asp:Button runat="server" ID="btnShowModal" Text="Show"
OnClick="btnShowModal_Click" />
<asp:Button runat="server" ID="HiddenForModal" style="display: none" />
<ajaxToolKit:ModalPopupExtender ID="Modal1" runat="server"
TargetControlID="HiddenForModal" PopupControlID="PopupPanel" />
In your message handler in code-behind, you'll show the ModalPopupExtender:
Modal1.Show();
And in the code you're using to dismiss the Modal, call the ModalPopupExtender's Hide function:
Modal1.Hide();
I use this method for showing a modal that displays detailed data that I retrieve from a database based on what's selected in a GridView.
Add your Button or LinkButton
<asp:Button ID="MyButton" Text="Click Here" runat="server" />
Add a Panel to hold your options with a DropDownList
<asp:Panel ID="MyPanel" runat="server">
<asp:DropDownList ID="MyDropDown" runat="server">
<asp:ListItem Value="1" Text="Option 1" />
</asp:DropDownList>
<asp:Button ID="SaveBtn" Text="Save" OnClick="Save_Click" runat="server" />
<asp:Button ID="CancelBtn" Text="Cancel" runat="server" />
</asp:Panel>
Add your ModelPopupExtender
<act:ModalPopupExtender ID="Mpe1" TargetControlID="MyButton"
CancelControlID="CancelBtn" PopupControlID="MyPanel" runat="server" />
Then add your code behind to the SaveBtn Button
public void SaveBtn_Click(object sender, EventArgs e) {
string selectedOption = MyDropDown.SelectedValue;
}
Finally, I've decided to use jQuery to show a ModalPopUp. The following question has the answer to this question:
jQuery UI's Dialog doesn't work on ASP.NET
If you are not agree, tell me.