Modalpopupextender not firing - c#

I am doing research to the Modalpopupextender from the Ajax Toolkit.
This code doesn't work, it doesn't open the pop-up. The only thing what happens when I click on the button is: Refreshing the page.
What am I doing wrong? Also tried this with an Updatepanel... Did 3 hours of research before posting this question, please don't blame it on me...
I also used the Toolkitscriptmanager, but that didn't solve it.
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Button ID="btnTest" runat="server" Text="Button" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnTest" PopupControlID="Panel"></asp:ModalPopupExtender>
<asp:Panel ID="Panel" runat="server">
<h1>Hello World!</h1>
</asp:Panel>

Use PostBackTrigger for the button and then check it out .:)
Example:
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnTest" runat="server" Text="Button" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnTest" PopupControlID="Panel"></asp:ModalPopupExtender>
<asp:Panel ID="Panel" runat="server">
<h1>Hello World!</h1>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnTest"/>
</Triggers>
</asp:UpdatePanel>

Related

FileUpload.hasFile returning false inside update panel

I have been through several links but didn't find anything helpful. I know it has been asked several times here.
Here is my frontend code
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload runat="server" ID="fuItemImage" Width="370px" TabIndex="12" />
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
Here is the backend code
if (fuItemImage.HasFile)
{
MyFunction.UploadThisFile(anything)
}
When I upload any image and click on the save button it shows false in FileUpload.HasFile. I am stuck and finding no solution for it.
Any help would be appreciated.
you can try this
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload runat="server" ID="fuItemImage" Width="370px" TabIndex="12" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID = "Button1" />
</Triggers>
</asp:UpdatePanel>
add the button id in triggers to upload the file which will do postback

reload on button click in

Here is my aspx:
<asp:Panel ID="pnl_updateClinicVisit" runat="server" CssClass="modalPopupClinicVisitEntry2" DefaultButton="bt_editClinicVisit_submit" Style="display:none">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button AutoPostBack="false" UseSubmitBehavior="false" ID="AddMedicationChange" ClientIdMode="Static" runat="server" Text="Add Med Change" OnClick="AddMedicationChange_Click" />
<asp:Panel ID="AddNewMedicationPanel" runat="server">
<asp:TextBox ID="NewDrugName" OnTextChanged="NewDrugName_TextChanged" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="NewDrugNameAutoCompleteExtender"
runat="server"
TargetControlID="NewDrugName"
MinimumPrefixLength="1"
EnableCaching="false"
CompletionSetCount="1"
CompletionInterval="500"
ServiceMethod="GetDrugs">
</asp:AutoCompleteExtender>
<asp:DropDownList OnSelectedIndexChanged="NewDrugChange_SelectedIndexChanged" ID="NewDrugChange" runat="server">
<asp:ListItem>Drug +</asp:ListItem>
<asp:ListItem>Drug -</asp:ListItem>
<asp:ListItem>Dose ↑</asp:ListItem>
<asp:ListItem>Dose ↓</asp:ListItem>
</asp:DropDownList>
<asp:Button AutoPostBack="false" UseSubmitBehavior="false" ID="SubmitMedChange" runat="server" Text="Add to Visit" OnClick="SubmitMedicationChange_Click" />
</asp:Panel>
<asp:ModalPopupExtender ID="updateClinicModalPopupExtender" runat="server" TargetControlID="bt_editClinicVisit_dummy"
PopupControlID="pnl_updateClinicVisit" CancelControlID="bt_editClinicVisit_cancel"
DropShadow="true" BackgroundCssClass="modalBackground" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
For some reason my page is reloading when I click the "AddnewMdication" and "SubmitMedChange" buttons. When I have the AutoPostBack=false UseSubmitBehavior=false, the events fire and then the page reloads. If I don't have these attributes then the page reloads before the events even fire. How do I get AJAX functionality within this modal?
Try setting your Buttons as an AsyncPostBackTrigger. You can do this by adding in the Triggers section and declaring the UpdatePanel as a conditional update.
For example
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AddMedicationChange" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="SubmitMedChange" EventName="Click" />
</Triggers>
<ContentTemplate>
<%-- Your code here --%>
</ContentTemplate>
</asp:UpdatePanel>
What this should do is to explicitly declare that those two buttons as being Async.
If this doesn't work, will you please post the relevant code to your two button OnClick events? AddMedicationChange_Click and SubmitMedicationChange_Click
If you try to interact with controls outside of the UpdatePanel in your code-behind during an asyncpostback, odd things can start to happen.

Update Progress GIF Image Can't be displayed when i click on a button in Modal pop Extender

I have an issue that I can't display my update progress GIF image when I click button in Modal Pop Extender
the Aspx Code is :
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<img src="ajax-loader.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button2" runat="server" Text="Button" />
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</asp:Panel>
<asp:ModalPopupExtender PopupControlID="Panel1" TargetControlID="Button2" ID="mpeConfirm"
runat="server">
</asp:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
and in the code behind I wrote that simple code to be able to display the Progress :( :
protected void Button1_Click(object sender, EventArgs e)
{
Thread.Sleep(2000);
}
After 1 day of googling. I made it :) .The solution was easy and really marvelous .
First, I made a simple modification in the designer. I just moved the update panel inside Modalpop Extender panel control like the following:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<img src="ajax-loader.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Button ID="Button2" runat="server" Text="Button" />
<asp:Panel ID="Panel1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="panel" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:ModalPopupExtender ID="modalExtender" runat="server" PopupControlID="Panel1"
TargetControlID="Button2">
</asp:ModalPopupExtender>
On the other hand, I added that code block on the Modal Pop Extender Button:
protected void Button1_Click(object sender, EventArgs e)
{
string script ="document.getElementById(";
script += "'";
script+=Panel1.ClientID;
script += "'";
script+=").style.display='none';";
ScriptManager.RegisterStartupScript(this, this.GetType(), "A",script , true);
System.Threading.Thread.Sleep(2000);
}
Many thanks to "Hitesh Sharma" and his reply to a similar issue through that useful link :
http://forums.asp.net/t/1552551.aspx

triggered button cause fullpostback

I've got an updatePanel and a button which triggered in it.
However, the button causes full postback instead of partial one.
Here's my Code:
<asp:Button ID="cEvent" runat="server" Text="צור יום" Width="80px"
Height="40px" Font-Size="Medium" onclick="cEvent_Click" CausesValidation="false"/>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel id = "updatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cEvent" EventName="Click"/>
</Triggers>
<ContentTemplate>
<div id="yesEve" runat="server" visible="false" style="width:95%; float:right; margin-left:5%; padding-top:20px; margin-bottom:20px;">
<table id="mytable" cellspacing="0" runat="server">
</table>
</div>
<div id="errorMsg" runat="server" visible="false" style="width:100%; text-align:center; float:right;">
<asp:label visible="true" ID="msg1" Font-Size="Medium" runat="server" Font-Bold="true" Text = "היום נמחק בהצלחה"></asp:label>
</div>
<div id="noEve" style="width:100%; padding-top:20px; float:right; text-align:center; margin-bottom:20px;" runat="server" visible="false">
<asp:label visible="true" ID="stamLabel" Font-Size="Medium" runat="server" Font-Bold="true" Text = "לא קיימים ימים פתוחים"></asp:label>
</div>
<asp:LinkButton ID ="remove" runat="server"></asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
I really need some help with that... i'm searching for hours all over the web to find an answer.
Thanks, Matan
In the code behind, you can try adding this line:
ScriptManager.GetCurrent(Page).RegisterPostBackControl(Button1);
There is nothing wrong with your code, you have a conflict somewhere with code(ClientIDs) you haven't show us or a JavaScript error breaking the page.
Here's a template for how to do this from a microsoft tutorial page:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel</legend>
<asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br />
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
More information here:
microsoft tutorial

Why updatepanel triggers another updatepanel?

I have two update panels at my ajax page. This is first time I'm using updatepanel and I don't know what is wrong. I think only btnFilter's Click event must trigger the second update panel's content but changing combo values (which also hides/unhides btnFilter button) makes second updatepanel change content (at least I see transferred data with firebug & second updatepanel blinks sometimes). Online here.
<asp:UpdatePanel ID="upComparison" runat="server">
<ContentTemplate>
Brand:
<asp:DropDownList ID="ddlBrands" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddlBrands_SelectedIndexChanged"
AppendDataBoundItems="true">
<asp:ListItem Value="" Text="Please select a brand..." />
</asp:DropDownList>
<asp:Panel ID="pModels" runat="server" Visible="false">
Model:
<asp:DropDownList ID="ddlModels" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddlModels_SelectedIndexChanged" />
</asp:Panel>
<asp:Panel ID="pButton" runat="server" Visible="false">
<asp:UpdateProgress ID="upMain" runat="server" DisplayAfter="100">
<ProgressTemplate><img src="/Assets/Images/loader.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Button ID="btnFilter" runat="server" Text="Filter"
OnClick="btnFilter_Click" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upList" runat="server">
<ContentTemplate>
<asp:Repeater ID="rProducts" runat="server">
<ItemTemplate>some code here</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnFilter" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
By default, every UpdatePanel will be refreshed during every asynchronous postback.
To change this behavior, set the UpdateMode property to Conditional.

Categories