I have first this
<li><asp:HyperLink id="logoutBtn" NavigateUrl="login.aspx" Text="Logout" runat="server"><i class="fa fa-sign-out fa-fw"></i> Logout </asp:HyperLink></li>
But I think it goes first to the page before he runs the back code which is this.
public void logoutBtn_Click(object sender, EventArgs e)
{
Session.Clear();
Response.Redirect("../login.aspx");
}
So basically I can still access any site because the Session is not cleared.
How can I achieve that whenever I click the HyperLink the code is fired?
The purpose of a hyperlink is to navigate the user to another destination. (Plus, you don't have a click eventhandler attached to you hyper link, that will run your code behind.)
If you want to run server-side code use a good old button:
<asp:Button ID="logoutBtn" runat="server" onclick="logoutBtn_Click" Text="Logout" />
public void logoutBtn_Click(object sender, EventArgs e)
{
Session.Clear();
Response.Redirect("../login.aspx");
}
If you want to use an asp:Hyperlink control to logout the user, navigate him to a specific logout page:
<li><asp:HyperLink id="logoutBtn" NavigateUrl="logout.aspx" Text="Logout" runat="server"><i class="fa fa-sign-out fa-fw"></i> Logout </asp:HyperLink></li>
Create the logout.aspx page and in the Page_Load event, log the user out:
protected void Page_Load(object sender, EventArgs e)
{
Session.Clear();
Response.Redirect("../login.aspx");
}
Related
I have user control deriving from BaseUserControl class and Now I need to add button in UserControl file(ascx)
I have added following code snippet in ascx:
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click"/>
Below is the code sample of ascx.cs file
public partial class MyContol : BaseUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
// code to execute after button is clicked
}
}
But here the button event is not triggering and during debug I am able to see its hitting Page_Load event, please help me to resolve on this.
Regards
Anand
I have seen this type of thing many times. Try the following.
Remove the button from the ASCX side of the page.
Remove the C# btn submit method.
Save the page.
Now go into design view...
Add the button back, assign the name in design view.
In Design View double click on the button so that it created the C# method for you.
I tried to access a ListView function from client side by using onclick in <a href>tag. But it resulted in an error like this:
No overload for 'ListView1_ItemEditing' matches delegate 'System.EventHandler'
<a href="#" onServerClick="ListView1_ItemEditing" runat="server">
<img src="../admin/images/editbtn.png"alt="editbtn" class="editimgbtn" id="editdelete"/>
</a>
Code behind:
protected void ListView1_ItemEditing(object sender, ListViewEditEventArgs e)
{
//contents
}
I know I can access this by using a LinkButton, but I need to use <a href>instead of that, and the tag is set inside a ListView. So how can I solve this issue?
You are using the wrong method signature. The signature must be:
protected void ListView1_ItemEditing(object sender, EventArgs e)
{
//contents
}
By the way, why do you think you need to use an <a href> tag? An ImageButton control would be more appropriate:
<asp:ImageButton runat="server" OnClick="ListView1_ItemEditing"
ImageUrl="../admin/images/editbtn.png"
CssClass="editimgbtn" Id="editdelete" />
while implementing Logout event Page validation events were raising in My form and It stops Firing Logout Method
Need to stop page validation events when I call Logout Method using on ServerClick()
<li><span>Logout</span></li>
My Code :
protected void logout_ServerClick(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Session.Abandon();
Session.Clear();
Session.RemoveAll();
Response.Redirect("Login.aspx");
}
use CausesValidation="False"
<asp:LinkButton id="logout" runat="server" Text="logout" CausesValidation="False"> </asp:LinkButton>
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"
}
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");
}