?
Solved

How to programmatically click a link?

Posted on 2010-11-09
6
Medium Priority
?
794 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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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…
Suggested Courses

800 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