When select an item from dropdownlist it will open a file in new tab. There is no error. but when I click on link button,click event does not fire of link button.
Again dropdownlist SelectedIndexChanged event is fired when I click on link button.
When I select from dropdownlist , it open a file new tab but dows call javascript function "ResetTarget()"
- <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
- <script type="text/javascript">
- function ResetTarget()
- {
- alert('Yes');
- document.forms[0].target = '';
- }
- function SetTarget()
- {
- document.forms[0].target = "_blank";
- window.setTimeout("document.forms[0].target='';", 500);
- }
- </script>
- <asp:HiddenField ID="hidCSRF" runat="server" Value="" />
- <table align="center" class="SubFormWOBG" style="line-height: 25px; width: 100%">
- <tr>
- <td style="width: 40%">Application Code: </td>
- <td style="width: 60%">
- <asp:LinkButton ID="lnkApplicationCode" runat="server" CausesValidation="false" OnClick="lnkApplicationCode_click"></asp:LinkButton>
- </td> </tr>
- <tr runat="server" id="MandatAtt">
- <td>Mandatory Attchment:</td>
- <td>
- <asp:DropDownList runat="server" ID="ddlAttachment" AutoPostBack="true" OnSelectedIndexChanged="ddlAttachment_SelectedIndexChanged"> </asp:DropDownList>
- </td>
- </tr>
- </table>
- </asp:Content>
in c# file
- protected void Page_Load(object sender, EventArgs e) {
- if (!IsPostBack) {
- try {
- lnkApplicationCode.Text = "135";
- MandatAtt.Visible = false;
- ddlAttachment.Attributes["onchange"] = "SetTarget();";
- MandatAtt.Visible = true;
- } catch(Exception) {
- Response.Redirect("~/ErrorPage.aspx", false);
- } finally {}
- }
- }
- protected void ddlAttachment_SelectedIndexChanged(object sender, EventArgs e) {
- try {
- string[] arr = ddlAttachment.SelectedValue.ToString().Split(',');
- int int_attachmentCode = Convert.ToInt32(arr[0]);
- int int_attachmentSerialCode = Convert.ToInt32(arr[1]);
- NOCAPInternalUtility.INDAppViewFiles(Convert.ToInt64(lnkApplicationCode.Text.Trim()), int_attachmentCode, int_attachmentSerialCode);
- } catch(System.Threading.ThreadAbortException ex) {} catch(Exception) {
- Response.Redirect("~/ErrorPage.aspx", false);
- } finally {
- hidCSRF.Value = Convert.ToString(System.Guid.NewGuid());
- ViewState["CSRF"] = hidCSRF.Value;
- ScriptManager.RegisterStartupScript(this, GetType(), "function", "ResetTarget();", false);
- }
- }
- protected void lnkApplicationCode_click(object sender, EventArgs e) {
- hidCSRF.Value = Convert.ToString(System.Guid.NewGuid());
- ViewState["CSRF"] = hidCSRF.Value;
- try {
- long ApplicationCode = Convert.ToInt64(lnkApplicationCode.Text);
- Session["ApplicationCode"] = ApplicationCode;
- } catch(Exception) {
- Response.Redirect("~/ErrorPage.aspx", false);
- }
- }