Solved

How to programmatically click a link?

Posted on 2010-11-09
6
760 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
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now