ASP.NET frameset target to new frame - asp.net

I have an ASP.NET page in a frameset. I divided into 2 frames, 1.LEFTNAVI and 2.MAIN.
In the first frame (LEFTNAVI) I'm using a textbox and a button for the search engine in below tree menu. If I click the search button or menu it will display the result in the 2nd frame (MAIN) (that is, target=MAIN). Now the problem is, the application session ends, then I click the search button. It will display the login page to start the session, after login, it is displaying the LEFTNAVI frame text in MAIN frame. That is, the textbox, search button and tree menu is displayed in MAIN frame.
Below is the code I'm using in left.aspx.
<script type="text/javascript" language="javascript">
function pageSubmit()
{
var myForm = document.getElementById('form1');
myForm.target = 'main';
}
function KeyDownHandler(btn)
{
if (event.keyCode == 13)
{
event.returnValue=false;
event.cancel = true;
btn.click();
}
}
</script>
<body>
<form id="form1" method="post" runat="server">
<div id="searchFunc" runat="server">
<asp:TextBox
ID="txtSearch"
CssClass="txtbox"
onKeyDown= "KeyDownHandler(searchButt)"
runat="server"></asp:TextBox>
<asp:Button
ID="searchButt"
runat="server"
CssClass="smallbutton"
Text="Search"
onclick="searchButt_Click"
OnClientClick="pageSubmit()" />
</div>
<br />
<br />
<asp:TreeView
CssClass="treeview"
ID="tree"
runat="server"
LineImagesFolder="~/TreeLineImages"
ShowLines="True" ExpandDepth="1" >
<Nodes>
<asp:TreeNode Text="sample tree menu" Value="sam" SelectAction="Expand">
</Nodes>
</asp:TreeView>
</form>
</body>

You can use redirect url. in this case your login page should have a parameter in query string witch will demonstrate the page url that redirected to login page and sure login page should redirect to that page after successful login.
in this case login page should check for redirect url after successful login and automatically redirect to it. in your case, it will redirect to result page (not search page).
sample scenario :
private void DoLogin()
{
//write some code for user validation
if(loggedin) //login was successful
{
//redirect to page that redirected to login because of session end
var redirectUrl = Request.QueryString["redirectUrl"];
Response.Redirect(redirectUrl);
}
}
remember if you are using membership provider of asp.net it will do it for your.

Related

Opening Page In New Tab Updates Both Tabs

I am working with two files, Default.aspx and Beta.aspx.
In Default.aspx I have a button that navigates to a Beta.aspx
<telerik:RadImageButton ID="btn26" runat="server" Skin="Material" Text="26" OnClick="btnConfirm_Click26">
</telerik:RadImageButton>
protected void btnConfirm_Click26(object sender, EventArgs e)
{
string url = string.Format("Beta.aspx?year={0}&track={1}&event={2}&car=26&session{3}", hidYear.Value, hidTrack.Value, hidEvent.Value, hidSession.Value);
Response.Redirect(url);
}
I have the Beta.aspx form tag set up like so in order to force the page to load as a new tab:
<form id="form1" runat="server" class="SmallFont" target="_blank">
The button works, and loads the page in Beta.aspx as a new tab like I had hoped for, however the Default.aspx page that the button resides on also navigates to the same URL. I want Default.aspx to always stay on the same page, what am I missing here?
To open a new tab, there is no need to do a server round-trip. You need to move your button onto a separate html form, skip the aspx code and handle the click event using (client-side) JavaScript, like this:
<form id="form2" class="SmallFont" action="Beta.aspx" target="_blank">
<input type="submit" ID="btn26" Skin="Material" Text="26" />
<input type="hidden" name="year" value="{0}" />
<input type="hidden" name="track" value="{1}" />
</form>
or this: (which might not work as-well because of popup blockers)
<input type="button" ID="btn26" Skin="Material" Text="26"
OnClick="window.open('Beta.aspx?year={0}&track={1}&event={2}&car=26&session{3}', '_blank');" />
If you don't like the old-school JavaScript, there are more-modern ways, with jQuery or other frameworks, etc. HTML button onclick event
This should be a pretty easy problem, let's put few more details out here.
There is a form on default.aspx
<form id="form1" runat="server" target="_blank">
<asp:Button ID="btn26" runat="server" OnClick="btnConfirm_Click26" Text="26" />
</form>
The target is _blank, i.e. the new window, or tab will be opened.
The code of btnConfirm_Click26() of default.aspx has redirect
protected void btnConfirm_Click26(object sender, EventArgs e)
{
string url = string.Format("Beta.aspx?year={0}&track={1}&event={2}&car=26&session{3}", 0, 1, 2, 3);
Response.Redirect(url);
}
i.e. the form of default.aspx in first tab will be submitted to a new window to the same default.aspx and then redirected (in same second tab) to beta.aspx.
default.aspx (in first tab)
--> default.aspx (in new tab) --> redirects to beta.aspx
If you have no code in Page_Load() of default.aspx, it should "stay" as-is in the first tab and will not "navigate to beta.aspx". If you have code in Page_Load(), make sure you use if (!Page.IsPostBack) to execute code only once when default.aspx is loaded (and not when it is redirected to beta.aspx).
As mentioned earlier, redirect does not require to be executed on server and can be done via client script too.

How do I hide the "Register" link after user successfully logs in?

A user opens our web app and is automatically taken to the default page.
While on default page, if the user has not logged in or created an account, the Register or Login link is displayed at the top of the page.
<table bgcolor="#003366" width="100%">
<tr><td align="right"><span style=" color:darkOrange;font-weight:bold">Login or Register</span></td></tr></table>
This is fine.
However, after user successfully logged in, s/he is redirected to his/her page.
The problem is that the user clicks the default page for whatever reason, the Register or Log in link appears again.
Is there a way to hide this link as long as the user is logged in and only show it after the user logs off?
Thanks in advance for your help.
This is the change I made so far, added label control:
<table bgcolor="#003366" width="100%">
<tr><td align="right"><span style=" color:darkOrange;font-weight:bold"><label id="loginId" runat="server" Text="Login / Register"></label></span></td></tr></table>
Based on the fact that your link is pointing to a login.aspx page, I can see that you are probably using the Web Forms section of asp.net
Usually when working with Authentication and showing/hiding elements on a page within Web Forms, you can make use of some asp.net controls.
If you are using the build in .net Membership provider, then there is a control called the Login View. This is a simple control that allows you to show different content when a user is Logged in/out.
You can do something as simple as this;
<asp:loginview ID="Loginview1" runat="server">
<AnonymousTemplate>
Login / Register
</AnonymousTemplate>
<LoggedInTemplate>
Logout
</LoggedInTemplate>
</asp:loginview>
This will automatically show/hide the correct content.
You can also make use of any server side control and using the Visible property of this. So in your code you can set controls to be visible or not depending on the logged in status.
Also you could wrap your code within a <asp:Panel> then just show hide depending;
<asp:Panel id="pnlLoggedOut" runat="server" Visible="True">
<span style=" color:darkOrange;font-weight:bold">Login or Register</span>
</asp:Panel>
<asp:Panel id="pnlLoggedIn" runat="server" Visible="False">
<span style=" color:darkOrange;font-weight:bold">Logout</span>
</asp:Panel>
In your code behind you can show either or.
Another way is to just have your <a> tag as a server control. You can then update the text and hyper link depending on the logged in status.
<asp:HyperLink ID="hlLoginStatus" runat="server" NavigateUrl="Login.aspx" Text="Login / Register" />
In your code behind if the user is logged in, then you can change the NavigateUrl and the Text property.
If you want to maintain your code, as much as possible, then I recommend wrapping your markup with a control that can be accessed server-side, like this:
<asp:Panel id="PanelLogin" runat="server" Visible="True">
<table bgcolor="#003366" width="100%">
<tr>
<td align="right">
<span style=" color:darkOrange;font-weight:bold">Login or Register</span>
</td>
</tr>
</table>
</asp:Panel>
Now in your code-behind Page_Load event, you can check to see if the user has logged in or not. I suggest you store whether or not they are logged in cache (i.e. Session value IsLoggedOn). You will toggle the visibility of the ASP.NET Panel, based upon the value of IsLoggedOn, like this:
protected void Page_Load(object sender, EventArgs e)
{
bool isUserLoggedOn = (bool)Session["IsLoggedOn"];
if(isUserLoggedOn)
{
PanelLogin.Visible = false;
}
else
{
PanelLogin.Visible = true;
}
}
when the user logins upon successful login. you should keep his username in Session as
Session["user"] = username;
Now on page Load() check if Session["user"] is null then label.text = "register"
else = label.text = "";
hope it will help.

how to access iframe textbox id in current page?

Friends I have a Parent Page(default.aspx) that includes an iframe page(iframe.aspx) containing textbox in the field. The parent page contains the "Save" button. Now i want to get the values of iframe page while submitting the parent page. How can i access the iframe pages fields in parent page submit?
iframe.aspx page,,,,
In Iframe page i have two textbox,,
<asp:textbox id="txtfromdate" runat="server"></asp:textbox>
<asp:textbox id="txttodate" runat="server"></asp:textbox>
default.aspx page
<iframe id="iframebody" runat="server" src="iframe.aspx" style="width:900px; height:600px"></iframe>
<asp:button id="submit" text="save" runat="server" />
frdz how to access iframe page id(txtfromdate, txtTodate) in parrent page(default.aspx) when i click on button??
Try this javascript on the button click.
HTML
<input type="hidden" id="txtHidData" runat="server" />
Javascript
var iframe = document.getElementById('iframebody');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var usernameTextBox = innerDoc.getElementById('txtfromdate');
document.getElementById ( "txtHidData" ).value = usernameTextBox.value;
C#
string valueInCodeBehind = txtHidData.Value;
You can not access iframe's content with server side code.
For accessing content of iframe, you should use javascript.
In jquery, you can access it :
var iFrameContent = $('#iframebody').content();
var fromDate = iFrameContent.find('#txtfromdate').val();
var toDate= iFrameContent.find('#txttodate').val();
store it in hidden fields on page, and then access in server side code
Place two hidden fields on your aspx page. like
<asp:HiddenField id="hdffromdate" runat="server"></asp:textbox>
<asp:HiddenField id="hdftodate" runat="server"></asp:textbox>
Set values in these hidden fields like
$('[id$=hdffromdate]').val(fromDate );
$('[id$=hdftodate]').val(toDate);
in your submit button click event handler
protected void submit_Click(object sender, EventArgs e)
{
var fromDate = Convert.ToDateTime(hdffromdate.Value);
var toDate = Convert.ToDateTime(hdftodate.Value);
//...
}

How to set html button as default for ASP.Net form?

Well, I'm trying to make ASP.NET urls looking user-friendly, like it was explained in this question. So I created an ASP.Net form, and placed asp:textbox and asp:button on it. Also I set onclientclick attribute to call JS function which navigates to smart URL by setting windows.location.href. In Firefox it works well but in IE and Opera the browser first navigates to smart url but then it closes connection and sends a postback using an asp.net form action.
I tried to solve it using html button instead of server ones. It works, but the problem is that it can't be set as default for the asp.net form. So' if user clicks on it, it does its work. But if the user just presses enter when form is active, the form performs its action, so the button is not pressed and JS url rewriting doesn't occur. So how can I solve this problem?
My JS looks like this:
function searchRedirect() {
var query = $get('colSearch');
window.location.href = 'colSearch?q=' + query.value;
return false;
}
and in search.aspx i have
<form id="MainForm" runat="server" method="get">
<asp:TextBox id="colSearch" runat="server" Width="615px" CssClass="searchLine"></asp:TextBox>
<input id="Button1" type="button" value="Search!" onclick="searchRedirect();" class="search" />
I also tried with asp:button:
<form id="MainForm" runat="server" method="get" defaultbutton="submitReqBtn">
<asp:TextBox id="colSearch" runat="server" Width="615px" CssClass="searchLine"></asp:TextBox>
<asp:Button runat="server" Text="Search!" ID="submirReqBtn"
onclientclick="searchRedirect();" CausesValidation="False"
EnableViewState="False" UseSubmitBehavior="False"></asp:Button>
</form>
Your onclientclick event needs to return false;
The form accepts an attribute showing which of the buttons are set as default: use it as in
<form id="form1" runat="server" defaultbutton="Button1">
where Button1 is the id of a button on the page.

Firing the JQuery Dialog using an ASP.NET Button?

I have a Page which has a Control on it with 2 textboxes (username and password) and an asp:Button. If the user's membership is going to expire within 30 days and the button is clicked, I want the JQuery dialog to popup. Inside the JQuery dialog, I have some text and an asp:LinkButton. The link button has an event attached to it, but it is not being fired when I click it in the dialog box. Here is the script tags for the JQuery:
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="ui.core.js"></script>
<script type="text/javascript" src="ui.draggable.js"></script>
<script type="text/javascript" src="ui.resizable.js"></script>
<script type="text/javascript" src="ui.dialog.js"></script>
Here is the script the dialog: For testing, I am closing the dialog on Renew Membership click, but I actually want it to fire a method I create in asp.net to direct the user to a another page and pass a session variable.
<script type="text/javascript">
$(document).ready(function() {
$("#dialog").dialog({
// autoOpen: false,
modal: true,
buttons: { "Renew Membership": function() { $(this).dialog("close"); } }
});
});
</script>
<asp:Content ID="mainContent" runat="server" ContentPlaceHolderID="Content">
<div id="dialog" title="Membership Renewal">
<p>Uh Oh! Your membership is going to expire.</p><br />
<p>Hurry up and renew today!</p><br />
<asp:LinkButton runat="server" Text="Click Here to Renew"
onclick="Unnamed2_Click"></asp:LinkButton>
</div>
Here is the click event for the LinkButton:
protected void Unnamed2_Click(object sender, EventArgs e)
{
UserProfiles userProfile = (UserProfiles)Session["userProfile"];
Response.Redirect("~/Renew.aspx");
}
What should happen is that when the user clicks the sign-in button, it should popup up the dialog only if the days they have left to expire is <= 30 and if they do, they have the option of clicking the link in the dialog and going to a renew page where I want to pass it a Session variable with a Profile, but that is not being called, so I guess, I would like to know is how can I add the event handler of the button to the dialog and is there a way to set it so that it only comes up once, for example adding a cookie to the users browser and only showing it if they don't have a cookie set.
I believe this is more of an ASP.NET issue and not a jQuery dialog issue.
I wouldn't use the onClick and PostBackUrl within the same LinkButton. So, take off the PostBackUrl attribute and instead use
protected void Unnamed2_Click(object sender, EventArgs e){
UserProfiles userProfile = (UserProfiles)Session["userProfile"];
Response.Redirect("~/Renew.aspx");
}
If you only need to show the control when the user is > 30 days. I would create a user control.
jquery.renewDialog.js
$(document).ready(function() {
$("#dialog").dialog({
modal: true
});
});
RenewalUserControl.ascx
<asp:ScriptManager runat="server" id="ScriptManager1">
<Scripts>
<asp:ScriptReference Path="jquery.renewDialog.js" />
</Scripts>
</asp:ScriptManager>
<div id="dialog" title="Membership Renewal">
<p>Uh Oh! Your membership is going to expire.</p><br />
<p>Hurry up and renew today!</p><br />
<asp:LinkButton runat="server" Text="Click Here to Renew"
onclick="Unnamed2_Click" />
</div>
Login.aspx
<uc1:RenewalUserControl runat="server" ID="RenewalUserControl1" Visible="false" />
Login.aspx.cs
if (user.IsExpired)
{
RenewalUserControl1.Visible = true;
}

Resources