how to change the iframe by a buttonclick in asp.net? - asp.net

i have a homepage and it has a iframe..i want that after clicking the button sign in..the particualr iframe will have the user.aspx..but how to implement this in code behind of the user.aspx.cs on buttonclick?? i want work it for server side...and i have learnt that javascript function can't be used as i am wanting it in server side..
my asp button and iframe in home.aspx
<asp:Button runat="server" ID="signin" CssClass="signinbt" Text="Sign in" OnClick="signin_Click"/>
</div>
<iframe id ="iframestyle" src="homeframe.aspx" name="iframe_a" runat="server" style="margin-top:0px;width:100%;height:500px;"></iframe>
</div>
my codebehind
protected void signin_Click(object sender, EventArgs e)
{
iframstyle.Attributes["src"] = "userpage.aspx";
}
here showing that iframestyle doesn't contain in the present context..

try This
protected void btnChange_Click(object sender, EventArgs e)
{
iframestyle.Attributes["src"] = "homeframe.aspx"
}

Related

Closing an asp.net page from a div on the same page

I have an ASP.NET page that contains a div that displays a button. When the button is pressed the div disappears leaving just the ASP.NET page (which is itself a popup from another larger asp.net page)
The ASP.NET ASPX is here:
<div id="UpdateErrDiv" runat="server" class="msgBox" style="z-index: 2000; width: 250px" visible="false">
<div id="UpdateErrText" runat="server"></div>
<br />
<asp:Button ID="butCloseErrMsg" runat="server" CausesValidation="False" OnClick="butClose_Click" Text="Close" />
</div>
The code-behind is here:
protected void butClose_Click(object sender, EventArgs e)
{
UpdateErrDiv.Visible = false;
}
How do I close down the op-up asp.net page after the div disappears?
You would need to close the popup using Javascript. You can use something like this:
protected void butClose_Click(object sender, EventArgs e)
{
UpdateErrDiv.Visible = false;
Page.RegisterStartupScript("closeWindow", "window.close()", true);
}

ASP.NET passing variables from web form to code behind

i'm developing a web application for my company, but i'm coming up against a very simple problem that i don't now how to resolve. I search a lot on internet but i can't find anything.
I need to call a code behind method from an asp.net controls passing variables.
This is the method in the code behind (file.aspx.cs):
protected void SayHello(object sender, EventArgs e, String RandomName)
{
Response.Write(PrintedString);
}
And this is a asp.net control that call the method through OnLoad event :
<asp:Label ID="Label1" runat="server" Text="Hello" OnLoad="Visibility('ciao mamma')"></asp:Label>
What's wrong with this simple thing? Where i'm wrong?
Please answer to this simple question, it's driving me crazy...Thanks.
You can pass an argument to the event handler by the following way, but please note it will work for only asp button.
<asp:Button ID="btn" runat="server" Text="Click" OnCommand="btn_Command" CommandArgument="YourArgumentValue"/>
and then in the code behind file you do like this :
protected void btn_Command(object sender, CommandEventArgs e)
{
Response.Write(e.CommandArgument);
}
It will work for only asp button because they have a onCommand attribute with them.
whenever you will click on the button this code behind file code gets executed.
Hope this helps.
You can set the value to label on Page_Load event
You can use below code.
protected void Page_Load(object sender, EventArgs e)
{
string UserName="test";
Label1.Text="Hello "+ UserName;
}
Is this what you need?
Markup:
<asp:Label ID="lbl" runat="server"><%=SayHello("foo") %></asp:Label>
Code behind:
protected string SayHello(string name)
{
return "Hello " + name;
}

How to navigate to Facebook page in asp.net

I created my own site and my own Facebook page.
I add follow me button on site.
in that user have to follow me either on facebook or on twitter.
Problem: How to navigate user to first login page and then after successfull login to my facebook page
Place image and navigate to login page on image click like following:-
<asp:Button ID="imgbtnFaceBook" CausesValidation="False" runat="server" OnClick="imgbtnFaceBook_Click"/>
protected void imgbtnFaceBook_Click(object sender, EventArgs e)
{
Response.Redirect("yourLoginPageLink");
}
On login page check credentials and redirect to facebook page like following:-
protected void btnLogin_Click(object sender, EventArgs e)
{
// check login Credentials
Response.Redirect("yourFaceBookPageLink");
}
<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" />
<asp:Button ID="imgbtnFaceBook" CausesValidation="False" runat="server" OnClick="imgbtnFaceBook_Click"/>
protected void imgbtnFaceBook_Click(object sender, EventArgs e)
{
Response.Redirect("https://www.facebook.com/yourPageLink");
}

Howto add postbackurl equivalent property to <div runat="server" />

I need a div element to cause postback to the server. I can use window.location tough but then I think I won't be able to fire any event back on the server. How can I call the asp.net generated dopostback function properly? Thx in advance
The idea is that I place a linkButton, and then I use it from the Div
<form id="form1" runat="server">
<div>
<div runat="server" ID="txtTest" style="cursor:pointer;" >Click the div</div>
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" style="display:none;"></asp:LinkButton>
<br /><asp:Literal runat="server" ID="txtDebug"></asp:Literal>
</div>
</form>
and code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtTest.Attributes.Add("onclick", "__doPostBack('"+LinkButton1.ClientID+"','')");
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
txtDebug.Text = "click on div";
}

Not getting user input from TextBox

I'm starting to loose my nerves on some completely banal thing: I don't get user input from a TextBox :S
I do something like this (code behind aspx):
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this._presenter.OnViewInitialized();
}
this._presenter.OnViewLoaded();
txtBox1.Text = "blah";
}
protected void Button1_Click(object sender, EventArgs e)
{
//Do sth with txtBox1.Text but when I read it, it is still the same as when a loaded the page at Page_Load, So if I entered "blahblah" in the txtBox1 via browser the text I get when I debug or run is still "blah"
}
And the aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="InsertStudent.aspx.cs" Inherits="IzPT.Vb.Views.InsertStudent"
Title="VnosProfesorja" MasterPageFile="~/Shared/DefaultMaster.master" %>
<asp:Content ID="content" ContentPlaceHolderID="DefaultContent" Runat="Server">
<h1>Student</h1>
<p>
<table style="width:100%;">
<tr>
<td style="width: 139px">
Name</td>
<td>
<asp:TextBox ID="txtBox1" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</p>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Save" />
</p>
</asp:Content>
I also tried to do this with DetailsView and bind it to a list but when I read the values in the edit mode i had the same problem.
Any ideas?
You're setting the textbox Text property to "blah" on every Page_Load. Since ViewState has already been loaded at this point, you're overwriting whatever value the user entered.
If you only want to set the Text value one time, then make sure that you put it inside the if (!IsPostBack) check.
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this._presenter.OnViewInitialized();
txtBox1.Text = "blah";
}
this._presenter.OnViewLoaded();
}
Your problem is that you are changing Value in Page_Load!
Page_Load is run before Button1_Click.
Move code from Page_Load to this
protected override void OnLoadComplete(EventArgs e)
{
txtBox1.Text = "blah";
}
Or protect your code... like this
if (!this.IsPostBack)
{
txtBox1.Text = "blah";
}
Page_Load is being called during the post back which is resetting the value in your text box. Change to
if (!this.IsPostBack)
{
txtBox1.Text = "blah";
this._presenter.OnViewInitialized();
}
Personally i would have a property in the view to set the textbox value from the presenter. In OnViewInitialized() or OnViewLoaded().

Resources