Button inside asp:panel is not working properly - c#

I have an ajax extender in my aspx page.
I want to make the button do something in code behind when is pushed but my button inside the panel doesn't work.I created another button outside the panel and wrote the same thing to do and is working.
This is my button inside the panel:
<ajax:AccordionPane ID="AccordionPane1" runat="server">
<Header>Adauga titlu</Header>
<Content>
<asp:Panel ID="UserReg" runat="server" DefaultButton="but">
<cc1:Editor ID="Editor1" runat="server" width="500px"/>
<br /><br />
<asp:Button runat="server" ID="but" Text="Adauga Titlu" />
</asp:Panel>
</Content>
</ajax:AccordionPane>
This button is not working but the other button outside is working and they both do the same thing.Can you provide a solution?

Perhaps you are simply missing the OnClick attribute, like this:
<asp:Button runat="server" ID="but" Text="Adauga Titlu" OnClick="but_Click" />

Have you included the Asp ScriptManager?
http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.aspx

Related

When I use asp LoginView Role for Button then get an error

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

Radio button not visible in ASP.NET page

ASP.NET radio button is not visible in my page. I am using it inside ASP.NET ListView. I tried putting the radio button inside ASP.NET update panel content template as well. Please tell me what has gone wrong?
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:ListView ID="FraudCheckList_listView" runat="server">
<ItemTemplate>
<p class="fraud-step-title"><%#Eval("question")%></p>
<div class="row">
<asp:RadioButton
runat="server"
class="radio-inline col"
GroupName="govt"
Text="Low Risk"
></asp:RadioButton>
<asp:RadioButton
runat="server"
GroupName='govt'
Text="Medium Risk"
></asp:RadioButton>
<asp:RadioButton
runat="server"
GroupName='govt'
Text="High Risk"
></asp:RadioButton>
</div>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
Since you haven't shared how your code looks like, i am just assuming certain things. Just see if you have done this or not.
void Button_Click(object sender, System.EventArgs e){RadioButton.Visible=false;}
If incase its true or something your radiobutton will not be visible. In your case it must be hidden. So, make the variable of visible as **false ** So you can just change your code to this and try it out.
This you have to do it in your main code. not in your html code.
Thank You!

Duplicate web form on button click

I have an ASP web form that includes divs, checkboxes, textboxes, buttons and dropdowns. Backend is c#.
I have an "Add" button at the bottom that when clicked, I want it to duplicate my form below the existing one.
Other than copying my form multiple times and toggling visibility based on a button click, is there some way I can put my form in a class and call on it based on the button click? Or any other way? Would think gridview is an option but I use divs within the form which is not allowed in gridview.
For Example:
<form id="form" runat="server">
<asp:ScriptManager ID="MainScriptManager" runat="server" />
<asp:UpdatePanel ID="updatepnl" runat="server">
<ContentTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
<asp:Button ID="add" runat="server" Text="Add" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
The Add button can be moved outside of the update panel if necessary. But I would like to duplicate the form below the original via clicking the Add button. Would also be handy if I could have a remove option as well.

modal pop up extender

What I'm doing is creating a list of tickets using a ListView. One of the controls in the item template is a link button that shows the header of the ticket. When the user clicks the link button, I want to open a modal window that shows the ticket in readable format. To get the ticket, I'll be passing that page a variable and it'll do the rest; nothing complicated. The page will have 3 buttons and the windows needs to close when you click one of them.
Now, I figured out how to use the ModalPopupExtender from the Ajax tookit more or less. You create the panel in it's own div which stays hidden. I created a click event that basically uses a webclient to download the html from the page and insert it into that div's innerHtml. This seems to work the first time. But as soon as you click a different link, the page pukes and says something about it being in an illegal state.
I'm not sure if I'm going about this wrong, and I can't find any decent examples of how to do this. Well there's one, but the english is hard to understand and it's in VB instead of C#. Any help?
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<form id="form1" runat="server">
<div><asp:toolkitscriptmanager id="ToolkitScriptManager1" runat="server"> </asp:toolkitscriptmanager>
<br />
<asp:modalpopupextender dropshadow="true" okcontrolid="btnOk" cancelcontrolid="btnClose" runat="server" popupcontrolid="Panel1" id="ModalPopupExtender1" targetcontrolid="Button1" />
<asp:panel id="Panel1" runat="server" cssclass="modalPopup" style="display: none;"> This is basic modal popup. <br /><br />
<asp:Button ID="btnOk" runat="server" Text="Ok" /> <asp:Button ID="btnClose" runat="server" Text="Close Me" />
<iframe src="http://www.google.com"></iframe>
</asp:panel>
<asp:button id="Button1" runat="server" text="First Modal Popup" />
</div>
</form>

ASP.NET AJAX Control Toolkit: Show a ModalPopup and then do PostBack

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.

Categories

Resources