I want to pop up a new page in the main page of my application . The location must be in center,can't be sizable, it shouldn't be opened as a new tab in the main page , the bar with the options for : closing,minimize/miximize shouldn't be there.
Here is my code:
protected void Page_Load(object sender, EventArgs e)
{
HyperLink1.Attributes.Add("onclick", "window.open('WebForm1.aspx',null,'height=350, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=center,menubar=no')");
}
But....
It's sisable,location is not in not in the center of the page.
The page is opened in the main page but as a new tab.
I don't know how to remove the bar with : closing,maximize,minimize
Can someone help me?
Thanks
Try this:
protected void Page_Load(object sender, EventArgs e)
{
HyperLink1.Attributes.Add("onclick", "centeredPopup('WebForm1.aspx','myWindow','500','300','yes');return false");
}
<script language="javascript">
var popupWindow = null;
function centeredPopup(url,winName,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
popupWindow = window.open(url,winName,settings)
}
</script>
For more details - see this
Related
I'm passing the value to the next page using server.execute, but I'm unable to get that value into next page.
//this is WebForm1.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
Server.Execute("WebForm2.aspx");
}
//this is WebForm2.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = //what method should i use to get the vale from WebForm1.aspx.cs
}
Edit :
On page1 (Button click etc) :
Server.Execute("page2.aspx?v=" + YourEncryptFunction(TextBox1.Text));
On page2 (Page_Load) :
TextBox1.Text = YourDecRyptFunction(Request.QueryString[0]);
In my project, It consist two page. Those are Form1.cs,myusercontrol1.cs.
Form1 having Button. In Button_click event need to redirect Form1 to myuserontrol1.cs page.
This is my code:
private void button1_Click(object sender, EventArgs e)
{
// Code1
var destinationform = new myusercontrol1();
destinationform.Show();
// Code2
myusercontrol1 destinationformobj = new myusercontrol1();
destinationformobj.Show();
}
But it never redirect to myusercontrol1.cs page
Is this possible to redirect from Form to UserControl page?
Thanks in advance
Ok according to the comments you can do this to solve your problem with a form:
public frmUserControl : Form
{
private UserControl control;
public frmUserControl(UserControl control)
{
this.control = control;
this.Load += frmUserControl_Load;
}
public frmUserControl_Load(object sender, EventArgs e)
{
this.Controls.Add(control);
}
}
You also have to take care of a few things like the size of the new form and the position of your user control inside the form. I tried to find my old code for that but it was too old and I don't have it right now. So I hope it helps :)
I have a aspx page that needs to be open in new TAB in Internet Explorer (Request from firm. They're using only IE).
My problem is all I've tried open NEW WINDOW, but not Tab.
Here What I've done:
protected void btnPracGr_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "newPage", String.Format("window.open({0});", "'pgPracGr.aspx'"), true);
}
One more:
protected void btnPracGr_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "newTab", String.Format("window.open({0});", "'pgPracGr.aspx'"), true);
}
One more:
<asp:LinkButton ID="btnPracGr" runat="server" OnClientClick ="document.forms[0].target = '_blank';" onclick="btnPracGr_Click">Practice Group Reports</asp:LinkButton>
One More:
protected void Page_Load(object sender, EventArgs e)
{
btnPracGr.OnClientClick = String.Format("window.open({0});return false;", "'pgPracGr.aspx'");
}
Nothing works for me... All ways it open new window... Any help, please!
You can't force a link to open in a new tab instead of a new window.
There's an option in IE's properties to force popups to open in new tabs instead of new window, it's under "Internet Options" > "General" > "Tabs" > "When a popup is encountered..."
Then your tests should work.
Create a function on your aspx code,
<script type="text/javascript">
function MyFunction()
{
var myWindow = window.open("DestinationPage.aspx", "_blank", "", false);
}
</script>
then call it on your c# code
Control.Add("OnClick", "MyFunction()");
Ok im having a problem with the text boxes of my page holding values of the login info when i navigate to the start up page via the back button of the browser. i need the text boxes to clear when the page is loaded but when i use the code im using the text boxes stay equal to "" instead of the user input when the login button is clicked. heres my code.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack == true)
{
txtEmailLog.Text = "";
txtPasswordLog.Text = "";
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
PlayerModel plyrModel = new PlayerModel();
PlayerBLO plyrBLO = new PlayerBLO();
List<PlayerModel> models = plyrBLO.GetAllPlayers();
foreach (PlayerModel player in models)
{
if (txtEmailLog.Text == player.PlayerEmail && txtPasswordLog.Text == player.PlayerPassword)
{
Session.Add("Player", player);
Response.Redirect("PlayerMenu.aspx");
}
else
{
lblMessage.Text = "Invalid Login! Retry or Register.";
}
}
}
When ever your page is loaded the following script will run.Include script file jquery-1.4.1.js in your LogIn form it will work even when you click Browser Back Button.
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// clear the text box values onload.
$('#<%=txtEmailLog.ClientID%>').val('');
$('#<%=txtPasswordLog.ClientID%>').val('')
});
</script>
there are other ways, this is one of them
protected void btnLogin_Click(object sender, EventArgs e)
{
// rest of your code
txtEmailLog.Text = "";
txtPasswordLog.Text = "";
}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) // If page loads for first time
{
Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString()); // Assign the Session["update"] with unique value
//=============== Page load code =========================
//============== End of Page load code ===================
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["update"].ToString() == ViewState["update"].ToString()) // If page not Refreshed
{
//=============== On click event code =========================
Label1.Text = TextBox1.Text;
//lblDisplayAddedName.Text = txtName.Text;
//=============== End of On click event code ==================
// After the event/ method, again update the session
Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
}
else // If Page Refreshed
{
// Do nothing
}
}
protected override void OnPreRender(EventArgs e)
{
ViewState["update"] = Session["update"];
}
}
This is not working for high resolution gradient background.
Consider wrapping your button and the label in an updatepanel control, which uses AJAX to refresh their contents.
The rest of the page will not be reloaded and the action will not affect the browser navigation.
See this page on how an updatepanel control works.
Since you are handling the button click event in server side there has to be a postback to handle it.
If you do not want a post back to happen change the event handling to "client click"
//Heinzi code worked for me just made a small change in OnPreRender event, assign the ViewsState value when its not post back
protected override void OnPreRender(EventArgs e)
{
if (!IsPostBack)
{
ViewState["update"] = Session["update"];
}
}