Solved

How to programmatically click a link?

Posted on 2010-11-09
6
788 Views
Last Modified: 2012-05-10
Hi,
I have a link that when clicked wil prompt a popup window using jquery.

However, i would like to do the same in my code asp.net programatically. Basically, under certain logical algorithm, i want to trigger the click (just like as if i click it myself) to prompt the popup. The codes are below.

Please advise.

HTML
====
<a runat="server" href="#" id="ex3cTrigger">view</a> (notice)
...
<%--<div style="position: absolute; margin: -100px 0 0 100px;">--%>
<div style="position: absolute; margin: -100px 100 0 100px;">
<div id="ex3c" class="jqmNotice">
    <div class="jqmnTitle jqDrag">
      <h1>Did you know?</h1>
    </div>
 
  <div class="jqmnContent">
  <p>Pine, spruce, or other evergreen wood should never be used in barbecues. These woods, when burning or smoking, can add harmful tar and resins to the food. Only hardwoods should be used for smoking and grilling, such as oak, pecan, hickory, maple, cherry, alder, apple, or mesquite, depending on the type of meat being cooked.</p>
  </div>
 
  <img src="Image/clip_thumbnail.jpg" alt="close" class="jqmClose" />
  <img src="Image/clip_thumbnail_old.jpg" alt="resize" class="jqResize" />
</div>
</div>

JQUERY
=======
<script type="text/javascript">

    $().ready(function () {
    $('#ex3c')
    //.jqDrag('.jqDrag')
    //.jqResize('.jqResize')
    .jqm({
        trigger: '#ex3cTrigger',
        overlay: 0,
        onShow: function (h) {
            /* callback executed when a trigger click. Show notice */
            h.w.css('opacity', 0.92).slideDown();
        },
        onHide: function (h) {
            /* callback executed on window hide. Hide notice, overlay. */
            h.w.slideUp("slow", function () { if (h.o) h.o.remove(); });
        }
    });
    });

</script>
0
Comment
Question by:tangteng78
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 250 total points
ID: 34091021
add JS function:function ClickTriggerLink() {  document.getElementById('ex3cTrigger').click();}in your code behind C#:Page.ClientScript.RegisterStartupScript(  this.getType(),   "ClickTriggerLink",   "ClickTriggerLink();",  true);
0
 

Author Comment

by:tangteng78
ID: 34091055
Not working. This is what i had on my .aspx.vb and javascript. Supposely on the first load, i should be able to see the popup window
.aspx.vb
---------------

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Page.IsPostBack Then
Page.ClientScript.RegisterStartupScript(Me.GetType(), "ClickTriggerLink", "ClickTriggerLink();", True)
End If

End Sub
javascript:
---------------
function ClickTriggerLink() {
document.getElementById('ex3cTrigger').click();
}

$().ready(function () {
$('#ex3c')
//.jqDrag('.jqDrag')
//.jqResize('.jqResize')
.jqm({
trigger: '#ex3cTrigger',
overlay: 0,
onShow: function (h) {
/* callback executed when a trigger click. Show notice */
h.w.css('opacity', 0.92).slideDown();
},
onHide: function (h) {
/* callback executed on window hide. Hide notice, overlay. */
h.w.slideUp("slow", function () { if (h.o) h.o.remove(); });
}
});
});
0
 
LVL 8

Expert Comment

by:guvera
ID: 34091732
Hi,

 Please check the below condition

if (!ClientScript.IsStartupScriptRegistered(thisType,
"ClickTriggerLink"))
{
ClientScript.RegisterStartupScript(thisType,"ClickTriggerLink", "ClickTriggerLink();", True);
}
}
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 13

Expert Comment

by:devlab2012
ID: 34093782
In your original javascript code, add a line:
document.getElementById('ex3cTrigger').onclick();

Complete code will be:

<script type="text/javascript">

    $().ready(function () {
    $('#ex3c')
    //.jqDrag('.jqDrag')
    //.jqResize('.jqResize')
    .jqm({
        trigger: '#ex3cTrigger',
        overlay: 0,
        onShow: function (h) {
            /* callback executed when a trigger click. Show notice */
            h.w.css('opacity', 0.92).slideDown();
        },
        onHide: function (h) {
            /* callback executed on window hide. Hide notice, overlay. */
            h.w.slideUp("slow", function () { if (h.o) h.o.remove(); });
        }
    });
    document.getElementById('ex3cTrigger').onclick();
    });

</script>
0
 

Author Comment

by:tangteng78
ID: 34098866
Guvera, it doesn't work either.
devlab2010, adding the the line will cause the javascript to error out.
Any other ideas are greatly appreciated.
0
 
LVL 8

Assisted Solution

by:guvera
guvera earned 250 total points
ID: 34099290
Try this code in codebehind

                Dim strjscript As String = "<script language='javascript'>"
                strjscript += "ClickTriggerLink() "
                strjscript += "</script" + ">"
                ClientScript.RegisterStartupScript(Me.GetType, "ClickTriggerLink", strjscript)
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question