I am a using ASP.NET controller to display user detail. When RadWindow is open & I tried to close with Close button. But the problem is that after page load and post back it opens again and again. I've multi-option on page: new, save, print etc. search.
<telerik:RadWindow ID="rwReport" runat="server" Behaviors="Close" KeepInScreenBounds="true"
AutoSize="true" VisibleOnPageLoad="false" Modal="true" Title="Report ACMI Advance Payment"
DestroyOnClose="true">
<ContentTemplate>
<ucRPV:ReportViewer id="ucReportViewer" runat="server" />
</ContentTemplate>
</telerik:RadWindow>
cs file code
private void Print()
{
try
{
// this.sADPs.DisplayReport();
Hashtable reportParameters = new Hashtable();
reportParameters.Add("DataSourceName", "dsACMIAdvancePayment");
reportParameters.Add("reportName", "rptACMIAdvancePayment.rdlc");
reportParameters.Add("Id", this.hfId.Value.ToString().ConvertTo<long>());
this.ucReportViewer.clearReport();
this.ucReportViewer.showReport(reportParameters);
this.rwReport.VisibleOnPageLoad = true;
//showReport(reportParameters);
}
catch(Exception e)
{
throw e;
}
}
ASPX code:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxControlToolkit" %>
<%# Register Src="../Reports/rpvReportViewerPopup.ascx" TagName="ReportViewer" TagPrefix="ucRPV" %>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%# Register Src="../Common/UserControls/ToolBarActions.ascx" TagName="ToolBarActions" TagPrefix="ucTBA" %>
</td>
Do not use the VisibleOnPageLoad property to show a RadWindow, register a script that will call its show() method. Thus, subsequent postbacks will not cause it to show up by itself: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-opening-from-server.html.
Of course, preventing the form from re-submitting as Felice suggested is another thing that may also be needed.
To translate this into code:
instead of:
this.rwReport.VisibleOnPageLoad = true;
use:
string script = "function f(){$find(\"" + rwReport.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
You can try below code : this might help-
<telerik:RadScriptBlock runat="server" ID="scriptBlock">
<script type="text/javascript">
//<![CDATA[
function GetRadWindow() {
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow;
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
return oWindow;
}
function CloseWin() {
//Get the RadWindow
var oWindow = GetRadWindow();
//Call its Close() method
if (oWindow) {
oWindow.Close();
}
return false;
}
</script>
</telerik:RadScriptBlock>
And on Page: yourpage.aspx;... call the function onClientClick of button:
<asp:Button ID="btnClose" Text="Close" runat="server" CssClass="button" Enabled="true" OnClientClick="CloseWin();" />
I have experienced the same problem when you reload the page because the browser resend the information and the radwindow opens again. To avoid such behavior I have adopted the following solution:
Add a hidden filed to hold the client code:
<asp:HiddenField runat="server" ID="_repostcheckcode" />
Add the following code in the code page:
protected void Page_Load(object sender, EventArgs e)
{
CancelUnexpectedRePost();
}
private void CancelUnexpectedRePost()
{
string clientCode = _repostcheckcode.Value;
//Get Server Code from session (Or Empty if null)
string serverCode = Session["_repostcheckcode"] as string ?? "";
if (!IsPostBack || clientCode.Equals(serverCode))
{
//Codes are equals - The action was initiated by the user
//Save new code (Can use simple counter instead Guid)
string code = Guid.NewGuid().ToString();
_repostcheckcode.Value = code;
Session["_repostcheckcode"] = code;
}
else
{
//Unexpected action - caused by F5 (Refresh) button
Response.Redirect(Request.Url.AbsoluteUri);
}
}
The original article can be found here.
Add a Button with an OnClick handler with the following code:
protected void CloseRadWindow(object sender, EventArgs e)
{
rwReport.VisibleOnPageLoad = false;
}
Related
I have a button which i am trying to add a css class to appear disabled once the user has clicked it.
protected void Button_Continue_OnClick(object sender, EventArgs e)
{
Panel_Error.Visible = false;
Literal_Error.Text = "";
if (RadioButton_Yes.Checked)
{
...//if radio checked get text and process etc.
}
}
My button onlick is above which simply processes a textbox filled on the page.
My button looks like this:
<asp:Button runat="server" ID="Button_Continue" CssClass="button dis small" Text="Continue" OnClick="Button_Continue_OnClick" ClientIDMode="Static" OnClientClick="return preventMult();" />
And my javscript is as follows:
<script type="text/javascript">
var isSubmitted = false;
function preventMult() {
if (isSubmitted == false) {
$('#Button_Continue').removeClass('ready');
$('#Button_Continue').addClass('disabled');
isSubmitted = true;
return true;
}
else {
return false;
}
}
</script>
The problem I am having is that the css class added works fine on the first postback, but after which my button onclick doesnt work and the button cant be clicked again if the user needs to resubmit the data if it is wrong
Another problem I am having is that with a breakpoint in my method i notice that the method is fired twice on the click.
Looks like you need something like this:
private void Page_Load()
{
if (!IsPostBack)
{
//doNothing
}
else
{
//button.disabled = true
}
}
try this
<asp:Button runat="server" ID="Button_Continue" AutoPostBack="true" CssClass="button dis small" Text="Continue" OnClick="Button_Continue_OnClick" ClientIDMode="Static" OnClientClick="return preventMult();" />
During the page_load, I disable the timer. When I pressed Button1, I enable the timer, but the page refreshes. Therefore, it never reaches the timer_tick1. I need to show a popup after a certain amount of time a button is clicked. How do I prevent the refresh from happening?
Alerts Class
public static class Alert
{
public static void Show(string message, Page page)
{
// replaces the quotations to follow the script syntax
// quotations are interpretated as \\' in script code
string cleanMessage = message.Replace("'", "\\'");
string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";
// Gets the executing web page
Page tempPage = page;
// Checks if the handler is a Page and that the script isn't already on the page
if (tempPage != null & !tempPage.ClientScript.IsClientScriptBlockRegistered("alert"))
{
tempPage.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script); // this isn't working, but it works on a button click event.
}
}
}
Page Class
public partial class Test1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostback) {
Timer1.Enabled = false;
Label2.Text = "Panel refreshed at: " +
DateTime.Now.ToLongTimeString(); // Checks if page reloads
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{ // i added a breakpoint here. It doesn't even pass through.
Alert.Show("hehehehe", this); //PopUp Shows up.
Timer1.Enabled = false; //Cancels Timer
Label1.Text = "Panel refreshed at: " +
DateTime.Now.ToLongTimeString(); // Checks if update panel reloads
}
protected void Button1_Click1(object sender, EventArgs e)
{
Timer1.Enabled = true; //Starts Timer. It seems to refresh the page.
}
}
script
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Test1.aspx.cs" Inherits="Test1" %>
<%# Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
function delayer() {
setTimeout (function () {ShowPopUp()}, 15000);
}
delayer();
</script>
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000" Enabled="true">
</asp:Timer>
<asp:Label ID="Label1" runat="server" Text="PanelNotRefreshedYet"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="ShowPopUp();" />
</form>
</body>
</html>
I think you're confused. Timer1 is a server side control. So it will fire on the server side, if you're still processing the page, that is, and will have no effect on the client side. By the time it fires in your code, the page has likely already rendered so you'll see no effect from that Timer1 object's Timer1_Tick event. Since the page has completed rendering, you can't inject new JavaScript, modify the page, or anything like that. Remember that web development is a disconnected thing. You send a request, you get a response. There are no events by nature of the web. There are libraries out there for triggering events and such but I think that's way beyond what you're trying to achieve.
For client side "timer" you need to use JavaScript setTimeout method, which you have verified as working and is the proper way for you to achieve the delay you're looking to implement.
setTimeout (function () {ShowPopUp()}, 15000);
If you still want to do it in your Alert class, then get rid of Timer1 and have your Alert class inject the timeout in JavaScript:
protected void Button1_Click1(object sender, EventArgs e)
{
Alert.Show("He heee", this);
}
And in Alert, change your script to:
string script = "<script type=\"text/javascript\">setTimeout(function() {alert('" + cleanMessage + "');}, 15000);</script>";
Your button is doing a postback, so yes the page will be refreshed and your Page_Load function will run again. You should test for this using the IsPostback property.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostback) {
Timer1.Enabled = false;
Label2.Text = "Panel refreshed at: " +
DateTime.Now.ToLongTimeString(); // Checks if page reloads
}
}
You might want to look at showing the alert using JavaScript on the page rather than running it server side tho.
<script type="text/javascript">
function showPopup()
{
alert("Hey, click something already");
}
function delayer() {
setTimeout (showPopUp, 15000);
}
delayer();
</script>
Just put your message like this. Probably easier if your logic is simple.
I am developing a GIS web app (mapping) in C# ASP.net.
I have an Ajax TabContainer housing several TabPanels with a table. The table contains other content such as the map window, scale bar etc (all from the ESRI WebAdf toolkit).
Here's a slimmed down version of my table without the other content...
<table id="MainTable>
<tr>
<td>
<ajax:TabContainer runat="server" ActiveTabIndex="0" id="TabContainer" CssClass="ajax__tab_xp">
<ajax:TabPanel runat="server" HeaderText="Online Mapping Service" ID="TabPanel1">
</ajax:TabPanel>
<ajax:TabPanel ID="TabPanel2" runat="server" HeaderText="Postcode">
</ajax:TabPanel>
<ajax:TabPanel ID="TabPanel3" runat="server" HeaderText="Coordinates">
<ContentTemplate>
</ajax:TabPanel>
</ajax:TabContainer>
</td>
</tr>
</table>
On Postback at runtime my Tabcontainer sometimes dissapears. This issue is not browser specific.
So far I have tried with no success to...
Set Z-Index with Relative positioning for the TabContainer
Include a JQuery script to 'show' the TabContainer...
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#TabContainer").show();
});
</script>
Is there some C# I can include in the code behind along the lines of?...
Public void page_Load(object sender, EventArgs e)
{
TabContainer.show()
}
Fairly new to programming and trying to figure out how to 'always show' or 'always ontop' the TabContainer.
Thanks
I'm not sure if this is due to the fact that you cleaned your code before posting it here but you are missing tags.
The code on your aspx should look like this :
<AjaxToolkit:TabContainer ID="TabContainer" runat="server">
<AjaxToolkit:TabPanel ID="TabPanel1" runat="server">
<ContentTemplate>
Your asp/html code goes here
</ContentTemplate>
</AjaxToolkit:TabPanel>
</AjaxToolkit:TabContainer>
Ok, sorted this. There was an issue with the AJAX Toolkit not posting back client side...
<script language="javascript" type="text/javascript">
// Solution to sys.invalidoperationexception bug
Sys.Application.initialize = function Sys$_Application$initialize() {
if (!this._initialized && !this._initializing) {
this._initializing = true;
var loadMethodSet = false;
var initializeDelegate = Function.createDelegate(this, this._doInitialize);
if (document.addEventListener) {
loadMethodSet = true;
document.addEventListener("DOMContentLoaded", initializeDelegate, false);
}
if (/WebKit/i.test(navigator.userAgent)) {
loadMethodSet = true;
this._load_timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
initializeDelegate();
}
}, 10);
}
else {
/*#cc_on#*/
/*#if (#_win32)
loadMethodSet = true;
document.write("<script id=__ie_onload defer src=BLOCKED SCRIPTvoid(0)><\/scr" + "ipt>");
var deferScript = document.getElementById("__ie_onload");
if (deferScript) {
deferScript.onreadystatechange = function() {
if (this.readyState == "complete") {
initializeDelegate();
}
};
}
/*#end#*/
}
// only if no other method will execute initializeDelegate is
// it wired to the window's load method.
if (!loadMethodSet) {
$addHandler(window, "load", initializeDelegate);
}
}
}
Sys.Application._doInitialize = function Sys$_Application$_doInitialize() {
if (this._load_timer !== null) {
clearInterval(this._load_timer);
this._load_timer = null;
}
Sys._Application.callBaseMethod(this, 'initialize');
var handler = this.get_events().getHandler("init");
if (handler) {
this.beginCreateComponents();
handler(this, Sys.EventArgs.Empty);
this.endCreateComponents();
}
this.raiseLoad();
this._initializing = false;
}
Sys.Application._loadHandler = function Sys$_Application$_loadHandler() {
if (this._loadHandlerDelegate) {
Sys.UI.DomEvent.removeHandler(window, "load",
this._loadHandlerDelegate);
this._loadHandlerDelegate = null;
}
this._initializing = true;
this._doInitialize();
}
</script>
I want to delete a directory when its clicked on a hyperlink.I tried like the below.But my page redirecting to default(start) page and the directory is not deleting.
protected void Page_Load(object sender, EventArgs e)
{
Execute(s,Content,k,j);
}
private void Execute(string path,string cont,string sym,string space )
{
foreach (var directory in new DirectoryInfo(path).GetDirectories())
{
string f = directory.FullName;
f = Server.UrlPathEncode(f);
Response.Write("<a href =''" + "onclick='Delete(" + f + ")'> DELETE </a>");
Execute(directory.FullName,cont1,sym1,space1);
}
}
private void Delete(string path)
{
DirectoryInfo DirDel = new DirectoryInfo(path);
DirDel.Delete();
}
Can you tell me the problem in this code?
It is not clear from your question, where you have that folder, if it is on the client side, then i think it is not possible.
If it is on the server side you could use a link button instead of an anchor tag to run the code behind function
If you cant use the link button for some reason you could use JavaScript ajax calls to call the code behind function.
Here is a code project article, that may help you
You're rendering clientside code, expecting it to call serverside code. This will never work, clientside always happens on their machine, not on your server.
What you want is to use a LinkButton control, e.g.:
<%# Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>LinkButton Example</title>
<script language="C#" runat="server">
protected void LinkButton_Click(Object sender, EventArgs e)
{
// Code to delete directory
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>LinkButton Example</h3>
<asp:LinkButton id="LinkButton1"
Text="Click Me"
Font-Names="Verdana"
Font-Size="14pt"
OnClick="LinkButton_Click"
runat="server"/>
<br />
<asp:Label id="Label1" runat="server" />
</form>
</body>
</html>
The general problem is that you create client-side URLs, but method to call is server-side. So you need to create server-side URLs, and handle postback click:
string path = #"d:\Temp";
protected override void OnInit(EventArgs e)
{
string dir = this.Request["dir"];
if (String.IsNullOrEmpty(dir)) // write links
{
foreach (var di in new DirectoryInfo(path).EnumerateDirectories())
{
var link = new HyperLink()
{
Text = di.Name,
NavigateUrl = String.Format("?dir={0}", HttpUtility.UrlEncode(di.Name))
};
this.Controls.Add(link);
}
}
else // process link click
{
dir = HttpUtility.UrlDecode(dir);
path = Path.Combine(path, dir);
Directory.Delete(path);
Response.Redirect("~/Default.aspx"); // page's name to refresh content
}
}
You should use a LinkButton to get the same look as the , but you need your code to be execute on server side as the PostBack for your LinkButton.
The code you have here will make a call to a client-side script.
i am trying to use javascript events in asp.net webforms. but events for input controls like textfield, such as onClick, onFocus,onBlur, dont appear. do i need to change my directive:
<%# Page Title="" Language="C#" MasterPageFile="~/YourGuruMaster.master" AutoEventWireup="true" CodeFile="AskQuestion.aspx.cs" Inherits="AskQuestion" %>
i want to be able to do this:
//code page
protected void Page_Load(object sender, EventArgs e)
{
QuestionTextBox1.Attributes["onfocus"] = "ClearSearchText()";
//Markup page
function ClearSearchText() {
var searchUserName = document.getElementById('<%=QuestionTextBox1.ClientID%>');
if (searchUserName.value = searchUserName.defaultValue) {
searchUserName.value = "";
}
return false;
}
<p dir="rtl" style="">
<asp:TextBox ID="QuestionTextBox1" runat="server" Width="702px"
Text="פרטים עד 5000 תווים"></asp:TextBox>
Add onfocus and onblur into the markup as follows:
<asp:TextBox ID="TextBox1" runat="server" onfocus="TextBox1_focus(this, event)" onblur="TextBox1_blur(this, event)" Text="Search..."></asp:TextBox>
<script type="text/javascript">
var searchText = 'Search...';
function TextBox1_focus(sender, e) {
if (sender.value == searchText)
sender.value = '';
}
function TextBox1_blur(sender, e) {
if (sender.value == '')
sender.value = searchText;
}
</script>
Well, not sure which ASP.NET version you use. I think last versions allow this (rendering attributes that the server controls don't understand to the browser still). Try using "onfocus" instead (lower case).
However, if this is not working for you, then you have to do it from code behind...
protected void Page_Load(object sender, EventArgs e)
{
QuestionTextBox1. Attributes["onfocus"]="someJavaScriptMethod";
}
Alternatively, if you have jQuery in the page you can go something like ...
<script type="text/javascript">
$(function() {
$('#<%= QuestionTextBox1.ClientID %>').focus(someJavaScriptMethod);
});
</script>
If you do that, inside someJavaScriptMethod(), you can use the word this to point at the focused control, and you can create a jQuery object from it easily like $(this).
.
Please leave me a comment if none of the above solves your problem.