Frage

Well, I bet this is a case for "This works on my machine".

The problem is:

I have a LinkButton in my GridView:

<asp:TemplateField HeaderText="Website">
    <ItemTemplate>
        <asp:LinkButton ID="L_Website" CausesValidation="true" runat="server" Text='<%# Eval("L_Website") %>'
            CommandArgument="GoToWebsite" OnClientClick="return confirm('Are you sure you want to go to this Website?');"
            CommandName="GoToWebsite"></asp:LinkButton>
    </ItemTemplate>
</asp:TemplateField>

which I fill with data with a DataReader:

dr["L_Website"] = Convert.ToString(reader["L_Website"]);

Maybe you also want to see the GoToWebsitecode:

protected void GV_Contacts_RowCommand(object sender, GridViewCommandEventArgs e)
{
    string ID = string.Empty;
    string status = string.Empty;
    if (e.CommandName == "Edit")
    {
        //code here
    }
    else if (e.CommandName == "View")
    {
        //code here
    }
    else if (e.CommandName == "GoToWebsite")
    {
        LinkButton lb = (LinkButton)e.CommandSource;
        GridViewRow gvr = (GridViewRow)lb.NamingContainer;
        LinkButton LinkButton = gvr.Cells[8].Controls[1] as LinkButton;
        if (LinkButton.Text.Substring(0, 3) == "www")
        {
            System.Diagnostics.Process.Start(LinkButton.Text);
        }
        else
        {
            System.Diagnostics.Process.Start("www." + LinkButton.Text);
        }
    }
}

It works fine on the local machine. Its getting displayed, and if I click on it, the local version makes the confirmation, and then opens a new tab with this page. On the server (IIS 6.0) it also gets displayed right, then if I click on it, it also makes the confirmation, but then it doesn't open a new tab with the page.

If I change the CausesValidation, it also doesn't work.
If I have noOnClientClick, it also doesn't work.
If I go (hover) over the LinkButton, it shows me that it makes a postback.

Already thank you :)

War es hilfreich?

Lösung

You are not thinking "client / server" like.

What you are doing is starting a process. Which is working and visible on your local development machine, because you are sitting in front of the monitor and can see such processes.

You are very likely starting processes on the server as well, but there's nobody there to see them. Log onto the server and watch the task manager.

You must find a solution which opens a link on the client side of your code, not on the server side. (All that can be done with HTML and JavaScript, no PostBack necessary.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top