Bootstrap modal appearing when I click the Back Button - c#

I'm working on a webform using C# ASP .NET 4.5.
My modal is working great for the most part. I have a page called CustomerLookup.aspx that uses the bootstrap modal. But when I close the modal, navigate to my site's home page, and then click the back button to go back to my CustomerLookup.aspx page - the modal appears.
I don't know if it makes a difference, but these two pages use a different MasterPage.
I am using Bootstrap 3.0.0
Here is the JS code in my Site.Master
function openModal() {
$('#uxModal').modal('show');
}
Here is my code-behind on the button click event to pop up my modal:
protected void uxTestButton_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
}

I didn't get the same issue when I used an HTML button control - only with the asp:Button server control. I'm just going to get away from server controls altogether - like I'm supposed to.

Related

Call PageLoad of parent page after closing modal popup

I have a parent page to display the project details, and user enter part details by uploading a template in a modal pop-up.
To open the modal popup I'm calling this function
function importfile()
{
var url="SCN_UploadPart.aspx";
var selSCE=window.showModalDialog(url,'win','help:no;status:no;scroll:no;resize:no;dialogHeight:300px;dialogWidth:490px');
return false;
}
Earlier I was using OnClinetClick method of Uplaod Button to call this method, then the project page or parent page was automatically reloading. But now I'm calling it like this.
ClientScript.RegisterStartupScript(this.GetType(), "project", "<script language='javascript'>importfile();</script>");
onclick of same Upload Button.
I font why the page does not reload now. I want the page to be reloaded as I am showing the content in the parent page after uploading the parts.
Please suggest me the way to reload the Parent page on click of close in modalpopup.
U can refer below link its show the demo
http://codedisplay.com/automaticaly-refresh-parent-window-whenever-popup-window-is-closed/
http://www.mindfiresolutions.com/Refresh-parent-page-on-closing-modal-child-windowpopup-29.php
Hope it helps u

ASP.Net C# - Redirect to a page

I've got a 'menu' within a Master page which includes a number of image buttons with click events.
Within each click event, I want to redirect the user to a specific (Child) page. However, if the user is already on the correct (Child) page, I don't want to refresh the page and lose the entered data.
In the example below, I want to redirect the user to browse.aspx however, if the user is already on browse.aspx, I don't want to refresh it.
Is there a better way to do this than the following?
protected void ibtnBrowse_Click(object sender, ImageClickEventArgs e)
{
if (!Request.Url.Segments[1].ToString().Equals("browse.aspx"))
{
Response.Redirect("~/browse.aspx");
}
}
How about disabling the Image button on the page?
e.g.
When you are on browse.aspx, in code behind browse.aspx.cs you can disable the button.
ImageButton iBtn = (ImageButton)Page.Master.FindControl("ibtnBrowse");
iBtn.Enabled = false;
By having server side click events the page will always "refresh" when clicking on these buttons. However, if you are simply looking to avoid doing an unnecessary redirect in your code you can use:
HttpContext.Current.Request.Url.AbsoluteUri
or
HttpContext.Current.Request.Url.AbsolutePath
If you decide to use javascript to switch between pages you can use location:
location.replace("http://www.w3schools.com");
location.assign("http://www.w3schools.com");

How to close a modal window after a save in Asp.NET WebForms

I have some javascript code on my main page that opens a popup when a link is clicked on:
<script language="javascript">
function OpenResidentialAddressWin(subscriberContactRelationGid, routeId, btn) {
window.showModalDialog("SubscriberResidentialAddress.aspx" + BuildQueryStringValuesForSubscriber(subscriberContactRelationGid, routeId, returntxtReceiptDate().value), this, strWindowFeatures + ";scroll:no;dialogWidth:442px;dialogHeight:350px");
location.href = location.href;
}
</script>
So the above code opens up the page SubscriberResidentialAddress.aspx in a modal window (as well as passing a number of variables into this page)
Now this page is arranged in such a way that it either displays or edits information. (These are in separate divs that are displayed or hidden dependign on what buttons have just been pressed in the window).
Currently after a user makes a save to the information on the page it switches to display mode. Instead I want to close the modal window completely and reload the main page.
A colleague suggsested that I use a literal control on the aspx page of the modal window and write javascript to it after a successful save has been carried out. So I placed the following in the head section of the SubscriberResidentialAddress.aspx page:
<asp:Literal runat="server" ID="litCloseWind"></asp:Literal>
And then in the code behind in the function that is called when a save is carried out
protected void btnAddSave_Click(object sender, EventArgs e)
{
////// code related to saving
if (status.IsSuccessful)
{
litCloseWind.Text = "<script>this.close()</script>";
Response.Redirect(Request.Url.AbsoluteUri, false);
}
}
I have tried the above and also litCloseWind.Text = "window.close()"; but neither were successful in closing the modal window after a save is carried out.
Is this plan logically sound and have I just made an error somewhere or was this a bad way of doing it to begin with?
Why don't you register a script here, like this:
ClientScript.RegisterStartupScript(typeof(Page), "CLOSEWINDOW", "window.close();");
No need of putting any Literal Control here.
So your code will look something like this:
protected void btnAddSave_Click(object sender, EventArgs e)
{
if (status.IsSuccessful)
{
ClientScript.RegisterStartupScript(typeof(Page), "CLOSEWINDOW", "window.close();");
}
}

how to refresh parent window by using Javascript in .cs

How to refresh the parent window while closing the popup window(child window).
We are calling the java script functions in code behind to refresh the parent window by using page.ClientScript.RegisterStartupScript().But t is working fine in IE(internet explorer) but not working in Mozilla Firefox and Google Chrome.
In the Mozilla Firefox the pop up value is saving in the database but it is not updating into the parent page.If i did refresh manually the value is getting updating into the parent page. If i put debugger in RefreshPage()(javascript function) function in IE it is firing but not in Firefox.
The below code for call the javascript function in .cs class.
page.ClientScript.RegisterStartupScript(this.GetType(), "PopupSave", "<script>javascript:alert('" + dsMessage.Tables[0].Rows[0]["ErrorMessage"].ToString() + "');window.open('','_self','');window.close();window.document.forms[0].submit();</script>");
The above code RefreshPage() is the javascript function to refresh the page
i.e.
function RefreshPage() { window.document.forms[0].submit(); }
Please help me i tried with different scenarios but no output.
instead of RefreshPage() i used different functions
like reload(),
window.opener.forms[0].submit(),
likewise but still no output anyone knows please help me.
Try this function
on submit button click run this script
<script language='javascript'> window.opener.frames.location='somepage.aspx';window.close();</script>
this will help you !!!
Before trying to make js calls between windows.
Set 'document.domain' to the same value on both pages.
protected void ButtonClick(object sender, EventArgs e)
{
string closeAndRefreshScript = #"<script type='text/javascript'>
window.opener.location.reload();
window.close();
</script>";
base.Response.Write(closeAndRefreshScript);
}

Don't Change URL in Browser When Clicking <asp:LinkButton>

I have an ASP.NET page that uses a menu based on asp:LinkButton control in a Master page. When a user selects a menu item, an onclick handler calls a method in my C# code. The method it calls just does a Server.Transfer() to a new page. From what I have read, this is not supposed to change the URL displayed in the browser.
The problem is it that the URL changes in the browser as the user navigates the menu to different pages.
Here is an item in the menu:
<asp:LinkButton id="foo" runat="server" onclick="changeToHelp"><span>Help</span>
</asp:LinkButton>
In my C# code, I handle the event with a method like:
protected void changeToHelp(object sender, EventArgs e)
{
Server.Transfer("Help.aspx");
}
Any ideas how I can navigate through the menu without the browser's URL bar changing?
You can use iframes to make sure that URL of browser doesn't change.
In Page_Load you can change src attribute of iframe to help.aspx
Try Server.Execute("Help.aspx") instead. You can preserve the form if you need by using
Server.Execute("Help.aspx",true);

Categories