vendredi 31 juillet 2015

how to call button's click event from click of linkbutton of another page without post back in c# ASP.NET

i have a LinkButton in masterpage and on click of LinkButton , i am redirecting to, say, Page1.aspx . On Page1.aspx , i have a button1. On click of that button1, i am opening new window, not affecting data of the Page1.aspx.

but when i click on LinkButton of masterpage, redirecting to Page1.aspx and from code behind,clicking button1 , Page1.aspx 's data gets changed.

how to prevent this. i am providing my code..

LinkButton on Masterpage :

<asp:LinkButton ID="lnkAppointMent" runat="server" OnClick="lnkAppointMent_Click"><span>Appointment Scheduler </span></asp:LinkButton>

click Event of LinkButton :

protected void lnkAppointMent_Click(object sender, EventArgs e)
        {
            Session["PhoneCenter"] = "Appointment";
            Response.Redirect("PhoneMessage.aspx");
        }

PageLoad of redirecting page(PhoneMessage.aspx) :

    protected void Page_Load(object sender, EventArgs e)
                {
                    fillCustomTypeMessages();            
                    if (!Page.IsPostBack)
                    {
                        .

    .

    .
                        else if (Session["PhoneCenter"].ToString() == "Appointment")
                        {
                            btnScheduleAppointments_Click(btnScheduleAppointments, null);
                        }

.

.

.

RaisPostBack method on PhoneMessage.aspx :

protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument)
        {
            try
            {
                base.RaisePostBackEvent(source, eventArgument);
            }
            catch (Exception ex)
            {


            }

.

.

Click event of button :

protected void btnScheduleAppointments_Click(object sender, EventArgs e)
        {
            if (!Permissions.checkPermissions(Session["employeeloggedin"].ToString(), "PHMSGVMD"))
            {
                ScriptManager.RegisterStartupScript(this, Page.GetType(), "OnLoad", "alert('You must have the Phone Messages: View and Modify permission to schedule appointments!')", true);
            }
            else
            {
                string script = String.Format("openNewWin('" + "phonescheduler.aspx" + "')");
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "openNewWin", script, true);
            }

        }

Script :

function openNewWin(url)
        {
            alert(url);
            var open_link = window.open('', '_blank');
            open_link.location = url;
        }

Any clarification needed. please comment..

Aucun commentaire:

Enregistrer un commentaire