ModalPopupExtender not showing anything - c#

Here is the relevant part of the aspx file:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div id="containerForTopButtonsCenter">
<telerik:RadButton ID="bt_addNewSnpAtTop" runat="server" Text="Add New SNP" AutoPostBack="false" UseSubmitBehavior="false" OnClientClicked="clickedToCreateNewSNP" OnClick="bt_addNewSnpAtTop_Click" />
</div>
<atk:ModalPopupExtender ID="NewSnpsModalExtender" runat="server"
TargetControlID="bt_addNewSnpAtTop"
PopupControlID="NewSnpsPopupWindow"
BackgroundCssClass="NewSnpsBackground"
OkControlID="NewSnpsOk"
CancelControlID="NewSnpsCancel"
DropShadow="true">
</atk:ModalPopupExtender>
<asp:Panel ID="NewSnpsPopupWindow" runat="server">
Hello! This is the Modal.
</asp:Panel>
When I click on the bt_addNewSnpAtTop button, no modal pops up. Also, the panel control NewSnpsPopupWindow shows up on the parent page (I was hoping that it would house the content displayed in the modal)...
All help is appreciated, thanks in advance.

I'm guessing the reason is related to your button also having onclick and onclientclick events.
In your OnClick event try:
bt_addNewSnpAtTop_Click(object sender, eventargs e)
{
//Other Code
NewSnpsModalExtender.Show();
}

Related

My button opens my modal popup window, but the c# codebehind connected to the button does not fire

I have a button that opens a modal popup, but before I open the modal popup, I want my "OnClick" event for the "btnSaveAndScheduleTask" button to fire. I am using ASP.NET 4.5 / Visual Studio 2012 / HTML5 / CSS3
My aspx (snipet):
How do I get the codebehind OnClick event for my "btnSaveAndScheduleTask" button to fire? If the entire code would help figure it out, let me know, but I'm probably missing something simple (bear in mind that I want to be able to view all my asp controls from the C# codebehind):
<asp:Button ID="btnSaveAndScheduleTask" runat="server" CausesValidation="true"
OnClientClick="javascript:return validatePage();" OnClick="btnSaveAndScheduleTask_Click"
Font-Bold="true" Text="Schedule Task" />
<ajaxToolkit:ModalPopupExtender ID="mpeScheduleTask" runat="server" ValidateRequestMode="Enabled"
BackgroundCssClass="modalBackground" CancelControlID="btnCancSchedule"
PopupControlID="pnlScheduleTask" TargetControlID="btnSaveAndScheduleTask" DropShadow="true" >
</ajaxToolkit:ModalPopupExtender>
<div id="divScheduleTask" runat="server">
<asp:Panel ID="pnlScheduleTask" Height="310" Width="690" BackColor="#ece4e1" ForeColor="Black" runat="server" >
<asp:UpdatePanel runat="server" ID="udpScheduleTask" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTaskSch" Visible="false" Font-Bold="true" Text="Task Scheduling: " runat="server" />
<asp:Button ID="btnSaveSchedule" runat="server" OnClick="btnSaveSchedule_Click" Text="Save Schedule" />
</div><asp:Button ID="btnCancSchedule" runat="server" Text="Canc" />
</ContentTemplate></asp:UpdatePanel></asp:Panel></div>
I've left out most of the panel as it's huge... here is my validatePage() Javascript:
<script type="text/javascript">
function validatePage() {
//Executes all the validation controls associated with group1 validaiton Group1.
var flag = window.Page_ClientValidate('vTask');
if (flag)
//Executes all the validation controls which are not associated with any validation group.
flag = window.Page_ClientValidate();
if (!Page_IsValid) {
$find('mpeScheduleTask').hide();
}
return flag;
}
</script>
My aspx.cs code behind:
protected void btnSaveAndScheduleTask_Click(object sender, EventArgs e)
{
//do stuff
}
Remove TargetControlID="btnSaveAndScheduleTask" , give other dummy control's ID
So when button clicks, click will take user to server , in code behind you need to manually open popup.
This is given here...!!!!
http://www.codeproject.com/Tips/215040/ModalPopupExtender-from-Server-Side-Code
I would put the javascript to be called in the behind code in your button click..
protected void btnSaveAndScheduleTask_Click(object sender, EventArgs e)
{
// do stuff.
Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "validatePage();", true);
}
this is how I do most of mine. Hope this helps.
And your ASP should look like..
<asp:Button ID="btnSaveAndScheduleTask" runat="server" CausesValidation="true" OnClick="btnSaveAndScheduleTask_Click" Font-Bold="true" Text="Schedule Task" />

ModalPopupExtender Hault Execution Until Ok is Clicked?

Perhaps I misunderstood the control, or very possibly am not implementing it correctly, but I've used a ModalPopupExtender much like I'd like to use a MessageBox in desktop development. The problem I'm running into is that once I call the Show() method of the ModalPopupExtender it continues to execute the server side code despite the fact that the user has not yet clicked the button set as the OkControlID. Is this the normal behavior, and or is there a way to hault code execution until the OkControlID has been clicked. To specify, I don't want to create another event in the button click handler as this popup is inline. Here is my code - any advice is appreciated.
My Control:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ModalMessage.ascx.cs" Inherits="LB.ModalMessage" %>
<asp:Button ID="btnPopup" runat="server" style="display: none;"/>
<ajaxToolkit:ModalPopupExtender ID="ModalMessageExtender" runat="server"
OkControlID="btnOkay" PopupControlID="Panel1"
TargetControlID="btnPopup" BackgroundCssClass="modalPopupBG">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel CssClass="whitebubble" ID="Panel1" style="display: none; max-width:400px;" runat="server">
<div style="padding:5px 5px 35px 5px;">
<asp:Label ID="lblMessage" Font-Size="Medium" runat="server" ForeColor="Black"/>
<br />
<asp:Button runat="server" Text="Ok" Width="75px" Height="30px" ID="btnOkay" CssClass="modalButton gray modalButton"/>
</div>
</asp:Panel>
The control code behind:
public void ShowMessage(string message)
{
this.lblMessage.Text = message;
ModalMessageExtender.Show();
}
My content page:
<%# Register Src="~/ModalMessage.ascx" TagName="ModalMessage" TagPrefix="mm" %>
<mm:ModalMessage runat="server" ID="mpeMessage"/>
My content code behind:
mpeMessage.ShowMessage("Please enter a username before attempting to reset your password.");
UPDATE:
Sorry for the lack of clarity - let me make my question more clear. If I do the following:
mpeMessage.ShowMessage("Please enter a username before attempting to reset your password.");
Response.Redirect("Register.aspx");
The redirect occurs and the ModalPopupExtender never gets shown. I'm somewhat new to web development so please forgive me if I'm using incorrect terminology. But essentially, I want the execution of code in the code behinds to wait for the user to click "Ok". I'm trying to replace something like this:
ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "alert('Your new account has been created!'); window.location='" + continueUrl + "';", true);
With something a little nicer looking, and since I'm already doing a postback anyway, I thought calling the ModalPopupExtender programmatically would be fine. Hopefully this clears up my question. Thank you all for your responses so far.
You can use validation controls , to check whether the fields are properly filled or not
for more details check the following links:
http://www.w3schools.com/aspnet/aspnet_refvalidationcontrols.asp
http://msdn.microsoft.com/en-us/library/aa479013.aspx
If i am understanding your query correctly then you want that until user does not click on "ok" button on modelpopup, user should not be able to click on page.
if you want this then add PopupDragHandleControlID="Panel1" in your modelpopup control.
<ajaxToolkit:ModalPopupExtender ID="ModalMessageExtender" runat="server"
OkControlID="btnOkay" PopupControlID="Panel1" PopupDragHandleControlID="Panel1"
TargetControlID="btnPopup" BackgroundCssClass="modalPopupBG">
</ajaxToolkit:ModalPopupExtender>
UPDATE
just replace Response.Redirect("Register.aspx"); to btnOkay click event.
on aspx page -
<asp:Button runat="server" Text="Ok" Width="75px" Height="30px" ID="btnOkay" OnClick="btnOkay_Click" CssClass="modalButton gray modalButton"/>
on aspx.cs page -
protected void btnOkay_Click(object sender, EventArgs e)
{
Response.Redirect("Register.aspx");
}
then until user will not click on "Ok" button. he/she can't redirect to Register Page.

asp.net how to close a dialoge box using intrapage linking in asp

I made a dialog box showing wrong password or username error but this doesn't close.
how to close this dialog box without refreshing the page,Code is like
<asp:Panel ID="errorMsg" runat="server" Visible="false">
<asp:Label ID="msg" Text="" runat="server"></asp:Label>
<asp:Label ID="errorHead" Text="Something is really Wrong :" runat="server"></asp:Label>
<asp:button ID="try" OnClick="try_Click" runat="server" Text="Try Again" />
</asp:Panel>
Code Behind :
protected void try_Click(object sender, EventArgs e)
{
errorMsg.Visible = false;
}
errorMsg.visible is set to true when wrong input is made but after making it again false it doesn't close.
The OnClick event will fire a PostBack refreshing the page.
You could try using javascript:
<script text="text/javascript">
function hide(id){
if(id)
document.getElementById(id).style.display = "none";
}
</script>
<asp:Button ID="try" OnClientClick='hide("<%=errorMsg.ClientId%>")'
runat="server" Text="Try Again" />
Or you could simply wrap the dialogbox with an Update Panel. The Update Panel allows you only to refresh a part of your website.
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="errorMsg" runat="server" Visible="false">
...
<asp:Button ID="try" OnClick="try_Click"
runat="server" Text="Try Again" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>

Not using asp listbox well

All I wish to do is simply click a button and the text in a textbox is automatically added as an item in the listbox. Shouldn't this be straight forward? Whilst debugging, the item is added and I can see the text by watching ListBox1.Items[0], but nothing is displayed in the web page. I had the same problem which i did not solve, in a console application! Can some one please guide me to what I am doing wrong?
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(new ListItem(TextBox1.Text));
}
Many thanks
Edit:
In a past project, I used the DataSource property, which worked perfectly. I have never yet managed to use the add Items! May be there is some sort of refresh or update?
Page code:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ListBox ID="ListBox1" runat="server" Height="150px" Width="295px"></asp:ListBox>
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
Looks like your listbox is outside of the update panel. Pop it inside the update panel:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="AddItem" />
</ContentTemplate>
</asp:UpdatePanel>
You have to move the ListBox into the UpdatePanel, otherwise it will not be updated.
The reason for that is, that ASP.NET is sending the whole HTML of the UpdatePanel back to the client. Since the ListBox is not part of the UpdatePanel, it won't be updated.

UpdatePanel not firing inside Wizard

I have an Update panel within a wizard:
<asp:WizardStep ID="WizardStep2" runat="server" StepType="Auto"
Title="Set the number of users required.">
...
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Always" runat="server">
<ContentTemplate>
<asp:Label runat="server" ID="ProgressInd" Text="Progress..." />
<asp:Button runat="server" OnClick="GoButton_Click" ID="ProgressBtn" Text="Go" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:WizardStep>
...
protected void GoButton_Click(object sender, EventArgs e)
{
ProgressInd.Text = "Progress... Moving";
}
When I take the update panel out of the wizard it works nicely but inside the wizard the click event just won't fire. I'm using Firefox to test, but IE doesn't work either. Any ideas or help appreciated.
For the record. Paolo spotted my problem. There were page validators that were preventing the event from firing.

Categories