We help IT Professionals succeed at work.

Link button not responsing to single click

I had to turn a link button from a hyperlink button becuase of the way i load a page it did not like the pre-render of the hyperlink, I turned it to a link button so that i can still pass values but it takes 2 clicks of the link button for it to work.  Then if I am on a pge and someone passes vlues to the link button and exports data and then they go back and pass another set of data, they agian have to click on it twice to get correct data.  I am just trying to pop-up another page and send session state to it to export to excel.  What am I doing wrong.


Protected Sub lnkExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkExport.Click
        Dim Type As Integer = 4
        Dim DepID As Integer = ddlDeployment.SelectedValue
        Dim BnID As String = ddlBn.SelectedValue
        Dim UICId As Integer
        Dim Cat As Integer
        Dim task As Integer
        Dim Pick As Integer = rbPick.SelectedValue

        If ddlUic.SelectedValue = Nothing Then
            UICId = 0
        Else
            UICId = ddlUic.SelectedValue
        End If

        If ddlCategory.SelectedValue = Nothing Then
            Cat = 0
        Else
            Cat = ddlCategory.SelectedValue
        End If

        If ddlTask.SelectedValue = Nothing Then
            task = 0
        Else
            task = ddlTask.SelectedValue
        End If

        If Pick = 0 Then
            Session("Type") = Type
            Session("SSN") = HFID.Value.ToString
            Session("Cat") = Cat
            Session("task") = task
        Else
            Session("Type") = Type
            Session("Pick") = Pick
            Session("DepID") = DepID
            Session("BnID") = BnID
            Session("UICId") = UICId
            Session("Cat") = Cat
            Session("task") = task
        End If

        lnkExport.Attributes.Add("onclick", "window.open('ExcelExport.aspx')")
    End Sub

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
You are adding attributes to the link button on its own click? Should that code not be somewhere else?

May be you want to replace this

lnkExport.Attributes.Add("onclick", "window.open('ExcelExport.aspx')")

with

Page.ClientScript.RegisterClientScriptBlock(Me, "Popup", "window.open('ExcelExport.aspx')", True)
HainKurtSr. System Analyst
CERTIFIED EXPERT

Commented:
ok, just do this for now, Line 43:

lnkExport.Attributes.Add("onclick", "window.open('ExcelExport.aspx')")

-->

response.write("<script>window.open('ExcelExport.aspx')</script>")

Author

Commented:
All,

OkNiether solution is working for me .
For Codecruiser I get a blue underline under teh Me  (value of reports_taskManage cannot be converted to system type)

hainKurt
Response.write will not work for me as it is in an update panel
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Is this all in a page? Me should translate to Page

Author

Commented:
CodeCruiser:

Ok see what you mean by it should be somewhere else, I changed it to my my on page load event and it works on single click now.
HainKurtSr. System Analyst
CERTIFIED EXPERT

Commented:
try this

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(pageLoaded);
function pageLoaded(sender, args){
  window.open('ExcelExport.aspx');
}

and comment out line 43

Author

Commented:
CodeCruiser:,

The page is within a masterPage format, so that might be the reason it did not work, I have had so much trouble using master pages, when it comes up using javscript events and exports.
HainKurtSr. System Analyst
CERTIFIED EXPERT

Commented:
it works on single click, but at the same time your server code works :)

so you open ExcelExport.aspx without running server code, without setting your session variables... this is not what you want...

probably in ExcelExport.aspx you are using those session variables, and this way they are not set yet...

this comment is for post 37065977

Author

Commented:
HainKurt:,

Don't like to use session variables and this is reason why, but I need to transfer sensitive data and don't wnat o do it thorugh the URl and get post will not work, I tired classes but sometimes they do not get iniliazed fro some reason.  But I need to find a new solution becuase when our server is slow the session varialbes seem not to work.  I need to figure out how to export to excel in a page that uses a master page in update panels.  So far I have olny had lots of problems and errors.  I am trying to encrypt URl right now and it works except for one little stinking number it doe snto like.  So if you have any advice, I'll take it.
Sr. System Analyst
CERTIFIED EXPERT
Commented:
ok, do this... use second form, and a button. when clicked set hidden variables and submit...

<form name=form1 runat=server ...>
...
<button onclick="export()">export</button>
</form>

<form id=frmExcel name=frmExcel src="ExcelExport.asp" target="_blank">
<input id=a name=a type=hidden>
<input id=b name=b type=hidden>
<input id=c name=c type=hidden>
</form>

<script>
function export(){
  var frm =  document.getElementById("frmExcel");
  document.getElementById("a").value = document.getElementById("<%=txtA.ClientID%>").value;
  document.getElementById("b").value = document.getElementById("<%=txtB.ClientID%>").value;
  document.getElementById("c").value = document.getElementById("<%=txtC.ClientID%>").value;
  frm.submit();
}
</script>

Author

Commented:
thanks for the help

Explore More ContentExplore courses, solutions, and other research materials related to this topic.