current code: Response.Redirect("DeviceInformation.aspx?arg=" + e.CommandArgument); which redirects to a page with a data grid. The argument is passed into a stored proc on a database and the infor is returned in a grid.

What i want, is the same thing, but, open it in a new page.

So something like: Response.OpenNewDamnPage("DeviceInformation.aspx?arg=" + e.CommandArgument); but unfortunatly that does not exsist.

Thanks in advance for any help!

Dani AI

Generated

Good call by to do the work in the browser. — the window was opening but the grid never bound because the argument you were passing contains characters that break a plain URL or the way the script was emitted. Common causes: a # in the value becomes a fragment and is not sent to the server, special characters break the JavaScript string, or the page is inside an UpdatePanel so a raw Response.Write won’t run correctly on the client.

Server-side, encode the value and register a startup script (don’t dump raw script with Response.Write). Example pattern to call from your command handler:

string arg = HttpUtility.UrlEncode(e.CommandArgument.ToString());
string url = "UsageInformation.aspx?arg=" + arg;
string script = string.Format("window.open('{0}', '_blank');", url);

if (ScriptManager.GetCurrent(Page) != null)
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "openWin", script, true);
else
    Page.ClientScript.RegisterStartupScript(GetType(), "openWin", script, true);

Or keep it entirely client-side: put the value into a data-arg attribute (set from RowDataBound) and open with encodeURIComponent so the browser sends the full string:

<script>
function openFromData(el) {
  var v = el.getAttribute('data-arg') || '';
  window.open('UsageInformation.aspx?arg=' + encodeURIComponent(v), '_blank');
  return false;
}
</script>

Troubleshooting checklist: view the generated link/script in page source, confirm the opened page’s Request.QueryString actually contains the full value, and if you’re using UpdatePanel prefer ScriptManager.RegisterStartupScript. Always URL-encode values (and escape for JS if embedding into script) to avoid truncation or injection issues.

Recommended Answers

All 3 Replies

hi use window.open in ur script dont redirect that page. then it willopen a seperate window.

<script language="javascript" type="text/javascript">
        function btnWeek_onclick()
    {
          window.open("date.aspx");
    }
    </script>

<body>
<asp:Button ID="Button1" runat="server" OnClientClick ="return btnWeek_onclick()" Text="Button"  />
</body>

Let me know if u face any problem further

I currently have this code:

<asp:LinkButton  ID="Label3" CommandName = "AssetName" runat="server" CommandArgument='<%# Bind("AssetName") %>' Text='<%# Bind("AssetName") %>'></asp:LinkButton>

I could make this code as you suggest:

<asp:LinkButton  OnClientClick ="return btnWeek_onclick()" ID="Label3" CommandName = "AssetName" runat="server" CommandArgument='<%# Bind("AssetName") %>' Text='<%# Bind("AssetName") %>'></asp:LinkButton>

<script language="javascript" type="text/javascript">
        function btnWeek_onclick()
    {
          window.open("date.aspx");
    }
    </script>

but on the windows.open("date.aspx") line i need something like
windows.open("date.aspx?args=" + commandArgument");

becuase i need to create the dynamic qurey string... So i guess my question is how do i do this? and where do i put the javascript method?

Alright well someone on a differant thred suggested this:

Response.Write("<script type='text/javascript'>window.open('UsageInformation.aspx?arg=" + e.CommandArgument + "','_blank');</script>");

and this works... kinda. It opens a new windows with the correct url:

http://localhost:4513/WebSite2/UsageInformation.aspx?arg=XFM_UG:#306:100099462

But the datagrid does not load!
The data grid is connected to a sql data source that automatically gets the qurry string and runs a stored procedure with it and returns the rows into the grid.
Anything else on the page shows up, but it's like the datasource didn't get the string or something...

Thanks for any help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.