[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to programmatically click a link?

Posted on 2010-11-09
6
Medium Priority
?
795 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:
Meir Rivkin earned 1000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

650 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