Show and Hide Modal Popup Extender Not working - c#

Hi all I have a modal popup extender set to a hidden linkbutton. So when I want to use it I am doing
protected void ProcessFileBtn_OnClick(object sender, EventArgs e)
{
WaitModalPopupExtender.Show();
//DO STUFF
WaitModalPopupExtender.Hide();
}
Process takes a while, but no Modal Pop Up extender shows, when I create a button just to do the show function it works, but when I add in this
protected void Test_Click(object sender, EventArgs e)
{
WaitModalPopupExtender.Show();
System.Threading.Thread.Sleep(5000);
WaitModalPopupExtender.Hide();
}
Nothing shows up. Any thoughts?

It won't work.
Why...??
First request sent to Server.
WaitModalPopupExtender.Show();----Executed---But no response send to Client
System.Threading.Thread.Sleep(5000);----Executed---But no response send to Client
WaitModalPopupExtender.Hide();----Executed---Now its time to send the response
Now you can expect the output that will be sent to the Client

Without seeing all of the code it's hard to tell, but I believe that the page is doing a PostBack when you click the linkbutton. When the page does a postback, it refreshes and therefore your ModalPopupExtender won't show. I think you're looking for and Ajax call to do what you want, which I'm pretty sure is showing a wait window while processing data.

Related

Clicking multiple times on the same redirect button in ASP.NET causes weird results

When I click multiple times on a button that performs a server-side redirect using ASP.NET, thing can get weird. Sometimes I get ViewState errors, other times the page is only partially loaded.
The code for the OnClick event of the button is simple:
HttpContext.Current.Response.Redirect(targetUrl);
If I have something like:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
Something();
}
}
in the page I'm redirecting to, the Something() function won't be called if the button is pressed more than once in rapid succession.
Is this normal? What could be the cause of these weird issues when pressing buttons multiple times quickly?
Ok as far as i know i could explain the weird result as below:
the first time you click the button, server will do the redirect and since its the first time you hit the page from another page it will not be a postback, but the second time you click the button in the server you will be already redirected and it will see the request as postback because on the server your already on that page, since its redirected you in the first time, at the end you will get the response of the last click which will be a postback in the server.
to avoid this issue, you should make a loading panel appear on the button, or disable the button before you go to the server using javascript.

server side click event doesn't fire on LinkButton when PostBackUrl property has been set to another page

I put a linkbutton control named as "Logout" on my webpage with VS 2010.
When users press the "Logout" linkbutton , I want the system to do two things.
First is to trigger a server side click event to do some things such clear all session variables etc..
Second is to redirect to user to another page such logon.aspx
So I wrote following codes
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
LinkButton1.PostBackUrl = "LogOn.aspx";
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Session.Abandon();
....
....
}
But when the programs runs , any user clicks the linkbutton.The codes of LinkButton1_Click never be executed, because the page has already been redirect to Logon.aspx page and never do the LinkButton1_Click()
My Question is why LinkButton1 offers PostBackUrl property and server-side click event , but it seems that they don't cooperate very well ~
This is because by setting the PostBackUrl you are saying that when the button is clicked that you want it to post to the LogOn.aspx page rather than posting back to itself. Since you are posting to LogOn.aspx you will never trigger the event.
Instead, you should use some type of redirect in your button click after your sesion.abandon.
Can you check if there's an event LinkButton1_Click subscribed to a LinkButton1's OnClick?
Then for your second concern since you're referring with ASP.Net, you can handle this with your Global.asax, where you will redirect any user to a login page every time session was destroyed. See reference links below:
1.) SessionStateModule.End Event
2.) Using Session in Global.asax

Why need to rebind Crystal Report

I have created a Crystal Report. It is working fine. Then I tried to use it in Asp.Net using
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
DisplayGroupTree="False" />
The first time, it works fine but when I click on the print button, the report disappears and gives an error. When I move my BindReport method out of if(!IsPostBack) then it starts working fine.
Below gives error when print button is clicked:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindReport();
}
}
But this works fine
protected void Page_Load(object sender, EventArgs e)
{
BindReport();
}
Can someone help me understand what is the reason?
Insofar as only the mouse click events of the CrystalReportViewer control can be serialized into ViewState, binding to a report class that can be serialized generates an insoluble problem when reloading pages:
1 If the report binding code is placed in a Not IsPostBack conditional block the mouse click events from ViewState are retained, but the binding of the report does not take place, and an exception is thrown.
2 If the report binding code is placed outside the conditional block, the report is bound correctly, but the contents of ViewState is crushed in the process, and mouse click events are lost.
Nota : This situation occurs most often when clicks are made in a report to several pages at the CrystalReportViewer control. The report continues then mysteriously back on page 1.
Solution
Put the binding code CrystalReportViewer control in the Init event
Link : http://msdn.microsoft.com/fr-fr/library/ms225455%28v=vs.90%29.aspx

Response.Redirect() disables back-button

As far as I understand, Response.Redirect("http://stackoverflow.com"); tells the browser to initiate a request to another URL.
One of the results of this is that the browser "remembers" the redirection, and allows pressing "back."
However, I have a website where Response.Redirect disables the ability to press the browser's "Back" button, as if the browser had opened a new window. (Browsing history is not forgotten, unlike with Server.Transfer.)
The redirection used to work properly in the past, so I suspect the problem has something to do with the IIS server (IIS7).
I apologize in advance if this question should be moved to ServerFault.com.
UPDATES:
Here is some code:
protected void btnClickMe_Click(object sender, EventArgs e)
{
// ...
// some server-side logic
// ...
Response.Redirect("NewPage.aspx?ProductID=" + idNum);
}
Regarding "disables the ability to press the browser's 'Back' button", what I meant is that the button cannot be pressed. Same as when you open a new window. The button is gray, and clicking it has absolutely no effect.
UPDATE 2:
This has been tested with IE6 and IE8.
The problem was NOT with the Response.Redirect();.
When I was on OldPage.aspx, I entered a new URL in the address bar. Once the browser loaded the new site, it disabled the back-button.
Conclusion: There is something wrong with OldPage.aspx, not the redirection to NewPage.aspx.
I still don't know why THIS happens, but this is an entirely different question.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) //check if the webpage is loaded for the first time.
{
ViewState["PreviousPage"] =
Request.UrlReferrer;//Saves the Previous page url in ViewState
}
}
protected void btnBack_Click(object sender, EventArgs e)
{
if (ViewState["PreviousPage"] != null) //Check if the ViewState
//contains Previous page URL
{
Response.Redirect(ViewState["PreviousPage"].ToString());//Redirect to
//Previous page by retrieving the PreviousPage Url from ViewState.
}
}

How to hide modal pop up on browser back button

I have an application where I will show Modal Popup on successful insert, update and delete. But after performing this when I move to next page and coming back to previous page on hitting browser back button the Modal Popup is getting displayed, I don't want to display this pop up on hitting back button. How can I solve this
protected void Page_Load(object sender, EventArgs e)
{
if (Page.PreviousPage==null) {mpeModalPopup.Show(); }
if (Session["Tasks"] == null)
{
Server.Transfer("login.aspx");
}
else
{
string strTasks = Session["Tasks"].ToString();
if (strTasks.Contains("205"))
{
if (!IsPostBack)
{
mpeModalPopUp.Hide();
funPageLoadData();
CheckPopup();
Session["url"] = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
}
}
else
{
ReturnBack();
}
}
}
You dont seem to have handled Page.IsPostBack boolean property on your page_load event.
if (Page.PreviousPage==null) {mpeModalPopup.Show(); }
For opening the popup (after postback) asp.net changes the html or inserts a javascript function to show the modal popup.
The only solution I know of is triggering an ajax postback (with an UpdatePanel) instead of a full postback when you click the button(s). This way the popup is loaded by an ajax call and won't display when you press the backbutton later on.

Categories

Resources