Im using an Ajax update panel with a c# multiline textbox which updates on a timer, but it keeps scrolling to the top, Ive tried setting maintainginscrollpositiononpostback to true and also tried various javascripts. The broswer im using is IE.
This is my asp code with a c# textbox on the form.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" Height="390px" TextMode="MultiLine" Width="836px"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
Im quite new to the updatepanel so maybe something is wrong there,, Thanks\
Please read this article. I think it will help you
Maintain Scroll Position after Asynchronous Postback
Related
I want to use an ASP webpage to monitor a realtime log file - I have found solutions using other technologies e.g frontail, but not using ASP.
I think I need to signalr for realtime communication, and I have spent a few hours now searching for ideas and solutions without any luck. All my searches return info about the ASP and signalr logs themselves.
How can I monitor and stream a log file or multiple log files to a webpage using ASP webforms?
you might consider the UpdatePanel / Timer polling approach.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
Your repeater, datalist, listview, or other databound control here.
</ContentTemplate>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick">
</asp:Timer>
Timer1_Tick is the server side method that should rebind the databound control.
I have a button that appears after a method in c# is completed:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="submit" runat="server" Text="Submit" OnClick="submit_Click1" visible="true"/>
<button runat="server" class="submit2" id="closeWidget" visible="false">Close</button>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="submit" EventName="Click"/>
</Triggers>
$('.submit2').click(function () {
$('.widly').removeClass('window');
})
The problem is that when my method makes '.submit2' visible, my jQuery script doesn't recognize when i click on it.. However if i make it visible=true before the method is run, it works perfectly well.
So my question is, how do i make this work, after i change the visibility to true?
When using
visible="false"
the control is removed from the HTML output. If you just want to hide it, you can use the display style instead:
<button runat="server" class="submit2" id="closeWidget" style='display: none;'>Close</button>
Then you can show it by removing the display style attribute.
I am having one master page that has one update panel.
Content place holder is within the update panel
Now i have child page which has a File upload control
To make work File upload control, i have to put Postback trigger.
But question is where i can put that Postback trigger ??
If i put Postback trigger in Master page than it will give me error that control does not found
and i can't put Postback trigger because child page has not other update panel
What is the solution for this problem ?
Simply wrap the FileUpload with an UpdatePanel, which don't do anything and hasn't any side effect but will solve the problem.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnSubmit" runat="server" Text="Button" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
I have a web page having asp.net button control and textbox. I want a confirm message box, when someone changes the content of textbox and click on button. If user click on yes then event of button should fire other wise nothing should happen. All I want is to implement AJAX call back, but it is not working with ASP.NET button control.
Just add the following code to your aspx code
<asp:Button ID="btn1" OnClientClick="return confirm('sure?');" runat="server" Text="Button" />
You can use the ConfirmButtonExtender of the AjaxControlToolkit for this purpose,
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/ConfirmButton/ConfirmButton.aspx
You can also do using Client Callback in ASP.Net, It is really nice feature in ASP.Net
Please refer to http://msdn.microsoft.com/en-us/library/ms178208.aspx. Hope it helps :)
Combining the use of OnClientClick with javascript's confirm as suggested by Pilgerstorfer Franz, with an update panel for the ajax request you mentioned...
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:TextBox ID="txtInput" runat="server"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="btnSubmit" OnClientClick="return confirm('Are you sure you want to submit?');" runat="server" Text="Submit" />
Should give you want you need.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload onchange="clickTheButton();" ID="FileUpload1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
Button 1 is outside the update panel and the javascript that gets run when a user adds a file in the upload box is this:
function clickTheButton() {
document.getElementById('<%= Button1.ClientID %>').click();
}
The problem is simple. FileUpload1.HasFile == false. I don't know why this is, but when I put it in the update panel it ceases to work.
I have seen some other threads on this. But none of them answer why this is happening, they just point to things you can download.
EDIT: Really my main reason for wanting to do this is so that I can get a ..Uploading File.. Tag to pop up while the client is uploading to the server and once it has completed, display it in a datalist. I just cant get the UpdateProgress to work.
Basically you just need to make your button do a full postback to send the file. Also make sure that you have this.Form.Enctype = "multipart/form-data"; set in your code, or you can put in that page. AsyncPostbacks don't work with files for security reasons as mentioned, without hacks. (I've never been able to get it to work).
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload onchange="clickTheButton();" ID="FileUpload1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
For security purposes, browsers don't let you post files via javascript. Imagine if I could write a little bit a javascript to asynchronously submit the contents of your My Documents folder to my server.
So javascript-ish methods of posting the form, like the XMLHttpRequest used by the UpdatePanel, won't work.
This post describes a decent work around if you're on 3.5 SP1. http://geekswithblogs.net/ranganh/archive/2009/10/01/fileupload-in-updatepanel-asp.net-like-gmail.aspx
And this post describes a couple work arounds if you'd prefer not to use the AjaxControlToolkit. http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx
File Upload will not work with a partial post back.
So just add this line at your page load
ScriptManager.GetCurrent(this).RegisterPostBackControl(this.YourControlID);
Or use PostBackTrigger.
<Triggers>
<asp:PostBackTrigger ControlID="YourControlID" />
</Triggers>
Or You need special AsyncFileUpload control as defined in AjaxControl Toolkit.
<ajaxToolkit:AsyncFileUpload OnClientUploadError="uploadError"
OnClientUploadComplete="uploadComplete" runat="server"
ID="AsyncFileUpload1" Width="400px" UploaderStyle="Modern"
UploadingBackColor="#CCFFFF" ThrobberID="myThrobber" />
You can check here.