Nagnath Kendre
asked on
How to redirect link page to new tab using onclick event not href attribute?
Hi,
i created dynamically html button server side using c# code and onclick() event , i am calling server side method() on page post-back ...in server side redirect method some parameters are used ...
I want to redirect page in new tab and keep existing page as it is, please provide your solution with onclick() event or server side code.
Server side dynamic html code created for link button:
fileTest.Append(" <span>");
fileTest.Append("<a id=\"lnkPsBtn" + TestCatBuilder.GetCategory ById(categ ory.Catego ryId).Name + "\" name =\"lnkPsBtn" + TestCatBuilder.GetCategory ById(categ ory.Catego ryId).Name + "\"onclick=\"SearchTestDat a('" + TestCatBuilder.GetCategory ById(categ ory.Catego ryId).Id + "')\" > ");
fileTest.Append(TestCatBui lder.GetCa tegoryById (category. CategoryId ).Name);
fileTest.Append("</a></spa n>");
Script code:
<script type="text/javascript">
function SearchTestData(someid) {
__doPostBack("lnkPsBtn" + someid, someid);
}
// Postback
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() !== false)) {
theForm.__EVENTTARGET.valu e = eventTarget;
theForm.__EVENTARGUMENT.va lue = eventArgument;
theForm.submit();
}
}
</script>
Test.Redirect(urlParams);
/// <summary>
/// this will redirect the current HttpContext to the route based on the parameters given
/// </summary>
/// <param name="parameters">some parameters</param>
public void Redirect(T parameters)
{
if (HttpContext.Current == null) return;
HttpContext.Current.Respon se.Redirec tToRoute(_ routeName, new RouteValueDictionary(param eters));
HttpContext.Current.Applic ationInsta nce.Comple teRequest( );
}
i created dynamically html button server side using c# code and onclick() event , i am calling server side method() on page post-back ...in server side redirect method some parameters are used ...
I want to redirect page in new tab and keep existing page as it is, please provide your solution with onclick() event or server side code.
Server side dynamic html code created for link button:
fileTest.Append(" <span>");
fileTest.Append("<a id=\"lnkPsBtn" + TestCatBuilder.GetCategory
fileTest.Append(TestCatBui
fileTest.Append("</a></spa
Script code:
<script type="text/javascript">
function SearchTestData(someid) {
__doPostBack("lnkPsBtn" + someid, someid);
}
// Postback
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() !== false)) {
theForm.__EVENTTARGET.valu
theForm.__EVENTARGUMENT.va
theForm.submit();
}
}
</script>
Test.Redirect(urlParams);
/// <summary>
/// this will redirect the current HttpContext to the route based on the parameters given
/// </summary>
/// <param name="parameters">some parameters</param>
public void Redirect(T parameters)
{
if (HttpContext.Current == null) return;
HttpContext.Current.Respon
HttpContext.Current.Applic
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
User agreed with the solutions.
ASKER
function testClickEvent() {
if (!theForm.onsubmit || (theForm.onsubmit() !== false)) {
theForm.target = "_blank";
}
}