i am facing problem with saving and uploading image.
this is my code:
asp:UpdatePanel ID="UpdatePanel1" runat="server"
ContentTemplate
div style="position: absolute; top: 53px; left: -22px;
input id="picupload" type="file" runat="server" onchange="File_OnChange(this)" style="visibility:
hidden;"
div
asp:Button ID="btnUpload" runat="server" Text="Button"
this is my javascript on which i am calling my btnupload event:
function File_OnChange(sender) {
document.getElementById('<%=btnUpload.ClientID%>').click();
}
ContentTemplate
**Triggers**
**asp:PostBackTrigger ControlID="btnsave"**
**/Triggers>**
**/asp:UpdatePanel**
this whole code is under update panel.i am having one save button and i want this data to be posted on server on btnsave button event.
but problem is when i am selecting image my page load event fires again and error is coming on this line:
string strName = picupload.PostedFile.FileName;
error is :Object reference not set to an instance of an object.
can anyone tell me why my page load event is firing second time??
plz plz plz plz
Related
I'm trying to add an item i receive from the server to a list in codebehind inside the SignalR hub.on method. After it gets added to the list, the update panel should update and show up on the front end. The item gets added to the list, but the updatepanel doesn't update. When i do a manual refresh of the page in the browser, then i can see the added item just fine. I also added a button to update the update panel after the hub.on method gets fired, and again it works fine. Just that when trying to update the updatepanel inside the hub.on method, nothing happens.
Note : The hub.on method is inside the Page_Load method.
This is the hub.on method :
SignalRService.ServerHub.On<string, string>("commandMessage", (param, param1) =>
{
if (param.Equals("addConnectedClient"))
{
string[] sUserDetails = param1.Split(',');
string sUserName = sUserDetails[2]; //The item i want to add
DEBUG_AddPendingUser(sUserName);
updatepanelusers.Update();
}
});
This is the aspx code of the updatepanel :
<asp:UpdatePanel ID="updatepanelusers" style="display: none;" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<div id="userspending" runat="server" class="exercisepage pageleft"></div>
<div id="usersaccepted" runat="server" class="exercisepage pageleft2"></div>
<div id="usersdenied" runat="server" class="exercisepage pageright2"></div>
</ContentTemplate>
</asp:UpdatePanel>
Any help would be greatly appreciated! As i can't wrap my head around why this is happening.
I have a div inside an UpdatePanel, this div is shown when a use click on an edit link. The submit buttons to save are inside this div. Now when the use click on the submit button everything is fine except that this div is automatically hidden! the visibility is changed client side using jQuery's show().
Why is the UpdatePanel hiding my div even though it was shown by me? I have tried to set the runat='server' and enableing viewstate but I am getting the same result.
How do I just tell the UpdatePanelto leave thediv` as it is prior to the submit?
Here is a mini project that shows the problem:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
edit
</div>
<div id="edit-div" style="display:none; border: 2px black solid;">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
<script>
$(document).ready(function(){
$('#edit-link').on('click', function () {
$('#edit-div').show();
});
});
</script>
The code for the submit button:
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.UtcNow.ToString();
}
The simplest solution to this problem would be: -
don't use jQuery to show edit-div
make edit-div a server control
convert your edit to an <asp:LinkButton> control, and in its server-side click event, show your edit div
The problem is that the UpdatePanel is restoring the original state as per the markup for the page; edit-div is not a server control and you are showing it via client script, the UpdatePanel is unaware of this and will always return you the original markup.
There are ways to get jQuery to play nice with UpdatePanels in these scenarios, but it is more involved than the simple solution above.
Hope that helps.
GOAL: Create a page that shows a loading image on button click, which disappears after the processing is complete.
ISSUE: I have a page with an Ajax UpdatePanel that initially works correctly, displaying a loading page on button click, and then displays a GridView. However, after that happens, the page constantly refreshes and returns my GridView to its original state (I do some manual column adjustments OnRowDataBound like adding a legend row, merging some cells, cell background color changes, etc.)
The page is structured like so:
I am trying to include an Ajax UpdatePanel that shows a loading image after the Generate Report button is pressed.
On the content page, I essentially wrap the user control (report control shown in blue above and named filterControl below) and the content (gridview defined in .aspx page and bound in the code-behind) in the update panel:
<asp:UpdatePanel ID="updatePanelControls" runat="server">
<ContentTemplate>
<uc:MultiLevelReportFilter ID="filterControl" runat="server"
ReportTitle="Default Title"
InvisiblePanels="pnlMonths,pnlPeriods,pnlBusinessGroups,pnlDisplay,pnlBrands"
DefaultAccountLevel="level4">
</uc:MultiLevelReportFilter>
<asp:LinkButton ID="thelink2" runat="server"></asp:LinkButton>
<asp:UpdateProgress ID="updateProgress" runat="server">
<ProgressTemplate>
<div id="dvProgress" runat="server" style="background-color: aliceblue; left: 40%; position: absolute; text-align: center; top: 35%; vertical-align: middle;">
<div id="Div1" runat="server" style="background-color: #ffffff; border: 4px solid #DBE5F1; height: 100px; padding: 5px; text-align: center; vertical-align: middle; width: 100px; width: 300px; z-index: 1002;">
<asp:Image ID="Image2" runat="server" Style="margin-top: 25px" Height="50px" Width="50px"
ImageUrl="~/Images/New/ajax-loader.gif" />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<% Gridview here composed of manually bound ItemTemplate columns %>
</ContentTemplate>
</asp:UpdatePanel>
I wanted to add a trigger on the content page for btnGenerate, the Generate Report button seen in the user control, but the page errors out because btnGenerate is not actually on the page, rather it's in the control:
A control with ID 'btnGenerate' could not be found for the trigger in UpdatePanel 'updatePanelControls'.
Is this structured incorrectly? Should I have the Ajax on the user control, or content page? I'm trying to follow this MSDN example, but it doesn't have any examples with master pages and user controls.
POSSIBLE REASON?: I should note that I am using an updatePanel on the master page to asynchronously update a label with the current time, like so:
<asp:Timer ID="Clock" runat="server" Interval="10000"></asp:Timer>
<asp:UpdatePanel ID="updatePanelClock" runat="server">
<ContentTemplate>
<asp:Label ID="ClockLabel" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Clock" EventName="Tick"></asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
Is this what's causing the constant refreshes?
EDIT: I've added the UpdateMode property and set it to Conditional on the content page where I'm calling the report control. However, the page is still refreshing incessantly.
Yes, the entire page lifecycle will execute for every updatepanel postback. Anything outside of that update panel will not be refreshed by what the server processed, but all the code will execute as if it were a full page postback.
try javascript function
function myFunction() {
var myVar = setInterval(function () { myTimer() }, 1000);
function myTimer() {
var d = new Date();
var t = d.toLocaleTimeString();
document.getElementById("Label1").innerHTML = "Current Time : " + t;
}
this function call on form body
<body onload="myFunction()">
I've a web form with some registration details. I've a submit button in a update panel on the same page. If the user doesn't enter anything and clicks on submit button, it should do validation on all the mandatory fields of the form and display a message showing what fields are missing.
As soon as enter submit button with out entering anything, it is doing validation but throwing an execption:
Microsoft JScript runtime error: Sys.InvalidOperationException: Could
not find UpdatePanel with ID
'ctl00_ContentPlaceHolder_Content_UpdatePanel_Submit'. If it is being
updated dynamically then it must be inside another UpdatePanel.
and my update panel with submit button becomes invisible. The code is:
<asp:UpdatePanel ID="UpdatePanel_Submit" runat="server" UpdateMode='conditional'>
<ContentTemplate>
<div style="font-size: 12pt; width: 938px; margin-top: 5px; border-top: ridge 2px gray;">
<div style="margin-top: 10px; width: 938px;">
<asp:Button ID="btn_submit" runat="server" ToolTip="Click here to submit your request."
Text='Submit Request' onclick="btn_submit_Click" />
<asp:LinkButton ID="btn_cancel" runat="server" ToolTip=''>Cancel</asp:LinkButton></span>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
What do I do to prevent my update panel from going invisible?
With UpdateMode Conditional, you either need to add ChildAsTriggers=true or add a Asyncpostback trigger to that button
Few Examples:
http://asp-net-example.blogspot.com/2009/11/ajax-updatepanel-how-to-use-updatemode.html
http://www.asp.net/web-forms/videos/aspnet-ajax/how-do-i-use-the-conditional-updatemode-of-the-updatepanel
I am having an issue when a page contains multiple ModalPopups each containing a ValidationSummary Control.
Here is the functionality I need:
A user clicks a button and a Modal Popup appears with dynamic content based on the button that was clicked. (This functionality is working. Buttons are wrapped in UpdatePanels and the partial page postback calls .Show() on the ModalPopup)
"Save" button in ModalPopup causes client side validation, then causes a full page postback so the entire ModalPopup disappears. (ModalPopup could disappear another way - the ModalPopup just needs to disappear after a successful save operation)
If errors occur in the codebehind during Save operation, messages are added to the ValidationSummary (contained within the ModalPopup) and the ModalPopup is displayed again.
When the ValidationSummary's are added to the PopupPanel's, the ModalPopups no longer display correctly after a full page postback caused by the "Save" button within the second PopupPanel. (the first panel continues to function correctly) Both PopupPanels are displayed, and neither is "Popped-Up", they are displayed in-line.
Any ideas on how to solve this?
EDIT: Functionality in each Popup is different - that is why there must be two different ModalPopups.
EDIT 2: Javascript error I was receiving:
function () {
Array.remove(Page_ValidationSummaries, document.getElementById(VALIDATION_SUMMARY_ID));
}
(function () {
var fn = function () {
AjaxControlToolkit.ModalPopupBehavior.invokeViaServer("MODAL_POPUP_ID", true);
Sys.Application.remove_load(fn);
};
Sys.Application.add_load(fn);
}) is not a function
Missing ";" in injected javascript. see answer below
Image of Error State (after "PostBack Popup2" button has been clicked)
ASPX markup
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<%--*********************************************************************
Popup1
*********************************************************************--%>
<asp:UpdatePanel ID="Popup1ShowButtonUpdatePanel" runat="server">
<ContentTemplate>
<%--This button will cause a partial page postback and pass a parameter to the Popup1ModalPopup in code behind
and call its .Show() method to make it visible--%>
<asp:Button ID="Popup1ShowButton" runat="server" Text="Show Popup1" OnClick="Popup1ShowButton_Click"
CommandArgument="1" />
</ContentTemplate>
</asp:UpdatePanel>
<%--Hidden Control is used as ModalPopup's TargetControlID .Usually this is the ID of control that causes the Popup,
but we want to control the modal popup from code behind --%>
<asp:HiddenField ID="Popup1ModalPopupTargetControl" runat="server" />
<ajax:ModalPopupExtender ID="Popup1ModalPopup" runat="server" TargetControlID="Popup1ModalPopupTargetControl"
PopupControlID="Popup1PopupControl" CancelControlID="Popup1CancelButton">
</ajax:ModalPopupExtender>
<asp:Panel ID="Popup1PopupControl" runat="server" CssClass="ModalPopup" Style="width: 600px;
background-color: #FFFFFF; border: solid 1px #000000;">
<%--This button causes validation and a full-page post back. Full page postback will causes the ModalPopup to be Hid.
If there are errors in code behind, the code behind will add a message to the ValidationSummary,
and make the ModalPopup visible again--%>
<asp:Button ID="Popup1PostBackButton" runat="server" Text="PostBack Popup1" OnClick="Popup1PostBackButton_Click" />
<asp:Button ID="Popup1CancelButton" runat="server" Text="Cancel Popup1" />
<asp:UpdatePanel ID="Popup1UpdatePanel" runat="server">
<ContentTemplate>
<%--*************ISSUE HERE***************
The two ValidationSummary's are causing an issue. When the second ModalPopup's PostBack button is clicked,
Both ModalPopup's become visible, but neither are "Popped-Up".
If ValidationSummary's are removed, both ModalPopups Function Correctly--%>
<asp:ValidationSummary ID="Popup1ValidationSummary" runat="server" />
<%--Will display dynamically passed paramter during partial page post-back--%>
Popup1 Parameter:<asp:Literal ID="Popup1Parameter" runat="server"></asp:Literal><br />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<br />
</asp:Panel>
<br />
<br />
<br />
<%--*********************************************************************
Popup2
*********************************************************************--%>
<asp:UpdatePanel ID="Popup2ShowButtonUpdatePanel" runat="server">
<ContentTemplate>
<%--This button will cause a partial page postback and pass a parameter to the Popup2ModalPopup in code behind
and call its .Show() method to make it visible--%>
<asp:Button ID="Popup2ShowButton" runat="server" Text="Show Popup2" OnClick="Popup2ShowButton_Click"
CommandArgument="2" />
</ContentTemplate>
</asp:UpdatePanel>
<%--Hidden Control is used as ModalPopup's TargetControlID .Usually this is the ID of control that causes the Popup,
but we want to control the modal popup from code behind --%>
<asp:HiddenField ID="Popup2ModalPopupTargetControl" runat="server" />
<ajax:ModalPopupExtender ID="Popup2ModalPopup" runat="server" TargetControlID="Popup2ModalPopupTargetControl"
PopupControlID="Popup2PopupControl" CancelControlID="Popup2CancelButton">
</ajax:ModalPopupExtender>
<asp:Panel ID="Popup2PopupControl" runat="server" CssClass="ModalPopup" Style="width: 600px;
background-color: #FFFFFF; border: solid 1px #000000;">
<%--This button causes validation and a full-page post back. Full page postback will causes the ModalPopup to be Hid.
If there are errors in code behind, the code behind will add a message to the ValidationSummary,
and make the ModalPopup visible again--%>
<asp:Button ID="Popup2PostBackButton" runat="server" Text="PostBack Popup2" OnClick="Popup2PostBackButton_Click" />
<asp:Button ID="Popup2CancelButton" runat="server" Text="Cancel Popup2" />
<asp:UpdatePanel ID="Popup2UpdatePanel" runat="server">
<ContentTemplate>
<%--*************ISSUE HERE***************
The two ValidationSummary's are causing an issue. When the second ModalPopup's PostBack button is clicked,
Both ModalPopup's become visible, but neither are "Popped-Up".
If ValidationSummary's are removed, both ModalPopups Function Correctly--%>
<asp:ValidationSummary ID="Popup2ValidationSummary" runat="server" />
<%--Will display dynamically passed paramter during partial page post-back--%>
Popup2 Parameter:<asp:Literal ID="Popup2Parameter" runat="server"></asp:Literal><br />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<br />
</asp:Panel>
Code Behind
protected void Popup1ShowButton_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
//Dynamically pass parameter to ModalPopup during partial page postback
Popup1Parameter.Text = btn.CommandArgument;
Popup1ModalPopup.Show();
}
protected void Popup1PostBackButton_Click(object sender, EventArgs e)
{
//if there is an error, add a message to the validation summary and
//show the ModalPopup again
//TODO: add message to validation summary
//show ModalPopup after page refresh (request/response)
Popup1ModalPopup.Show();
}
protected void Popup2ShowButton_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
//Dynamically pass parameter to ModalPopup during partial page postback
Popup2Parameter.Text = btn.CommandArgument;
Popup2ModalPopup.Show();
}
protected void Popup2PostBackButton_Click(object sender, EventArgs e)
{
//***********After This is when the issue appears**********************
//if there is an error, add a message to the validation summary and
//show the ModalPopup again
//TODO: add message to validation summary
//show ModalPopup after page refresh (request/response)
Popup2ModalPopup.Show();
}
This is an issue with using both ValidationSummary and ModalPopup.
see here: http://ajaxcontroltoolkit.codeplex.com/WorkItem/View.aspx?WorkItemId=12835
The problem is that there is a missing ";" between the two injected scripts.
Their solution is to create/use a custom server control that inherits from ValidationSummary, that injects a ";" into the page startup script to fix the bug:
[ToolboxData("")]
public class AjaxValidationSummary : ValidationSummary
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true);
}
}
Put all the <asp:ValidationSummary controls at the end of the document.
Error will be resolved.
Did you seto a different "ValidationGroup" of each popup (ValidationSummary + validators) ?
it seems there is bug in modal pop extender with validation summary in panel. to avoid the scenario always put the validation summary modal popup extender and panel at the bottom of code.
add the respective code at bottom of page
<%--This button causes validation and a full-page post back. Full page postback will causes the ModalPopup to be Hid.
If there are errors in code behind, the code behind will add a message to the ValidationSummary,
and make the ModalPopup visible again--%>
<%--*************ISSUE HERE***************
The two ValidationSummary's are causing an issue. When the second ModalPopup's PostBack button is clicked,
Both ModalPopup's become visible, but neither are "Popped-Up".
If ValidationSummary's are removed, both ModalPopups Function Correctly--%>
<%--Will display dynamically passed paramter during partial page post-back--%>
Popup1 Parameter: