[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HTML Controls question

Posted on 2005-04-26
15
Medium Priority
?
201 Views
Last Modified: 2010-04-07
Is there a way though a regular page link like this <a runat="Server" href="http://www.yahoo.com">This is a link </a> with runat server added to call an asp.net sub routine and pass whatever text is where "This is a link" to it for a SQL query??
0
Comment
Question by:NickMalloy
  • 8
  • 7
15 Comments
 
LVL 8

Expert Comment

by:thrill_house
ID: 13869335
Yes this is possible.  You just need to reference the control in the code behind by declaring it like this:

Protected WithEvents myHTMLlink As System.Web.UI.HtmlControls.HtmlAnchor


Some of the events have slightly different names, but you should be able to figure it out.  Just make sure the HTML control has a runat="server" attached to it.
0
 

Author Comment

by:NickMalloy
ID: 13869431
My link is going to be created from XML using XSL, so I won't know the name of the link.
0
 
LVL 8

Expert Comment

by:thrill_house
ID: 13869515
Can you explain the process you are using to get the data from XML to the asp.net page?  It's possible that you might be able to intercept it somewhere and do it.  
0
Technology Partners: 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!

 

Author Comment

by:NickMalloy
ID: 13869570
I have a form I am working on which will be filled out based on returns the company makes. Part of this form is vendor information. My users do not want to have to deal with dropdownlist since we have well over 5000 vendors. So I was thinking of implementing a search function like this

http://blog.bitflux.ch/wiki/LiveSearch

When the user types a vendor it will narrow down to the vendors name and the different contacts with that vendor. I want the user to be able to select the vendors name and have there contact information fill in the rest of the form. So some how from what name they click I need the contact information to fill in the rest of the form. So I want to hit a sub and fill in the rest of the information.
0
 
LVL 8

Expert Comment

by:thrill_house
ID: 13869607
What you can do is set up a literal where you want the link to be.  Then cause a postback to occur when they select a vendor.  On the event that happens when they select the vendor you can just set the contents of the literal to "<a href='" & vendorLoc & "'>" & vedorName & "</a>"

Something like that is a nice work around, and no one will know the difference.
0
 

Author Comment

by:NickMalloy
ID: 13869638
I don't think I quite understand that. Can you show me an example or point me to one.  Thanks
0
 
LVL 8

Expert Comment

by:thrill_house
ID: 13869669
Ok, so let me see if I understand you.  They will do a search for the vendor, which will cause a postback when they his the "search" button.

You will have a literal on your html side, lets just call it literal1

When you get the results from the search, just do this:
Literal1.text = "<a href='" & vendorLoc & "'>" & vendorName & "</a>"
Where vendorLoc is the URL you want to send the person, and vendorName is the name of the vendor


Or is this search feature done entirely client side?
0
 

Author Comment

by:NickMalloy
ID: 13869718
There is no postback to the server. If you look at the link above. When the user types letters on there keyboard it fires a javascript which will call a ASPX page. This page will load a dataset and then place it as XML. The XML is transformed into HTML using XSL and displayed in a DIV. The article above will explain it a little better I am sure. there is no postback from the users point of view.
0
 
LVL 8

Expert Comment

by:thrill_house
ID: 13869761
Ok I think I understand a little bit more of what you are trying to do.  Are you basically trying to implement a LinkButton in html?  It seems like you want something that looks like a hyperlink that will cause a postback event that calls a SQL query.  Is this correct?
0
 

Author Comment

by:NickMalloy
ID: 13869766
Yeap that is it.
0
 
LVL 8

Expert Comment

by:thrill_house
ID: 13869832
Ok, I've done something like this before... what I did was mimic what ASP.net does by manually calling a javascript method to do a postback (as the href).  I then check for the value that is thrown back on page load, and do work accordingly.  I will try and get an example for you.
0
 

Author Comment

by:NickMalloy
ID: 13869842
thank you. I will look forward to seeing your example
0
 
LVL 8

Expert Comment

by:thrill_house
ID: 13870349
Ok,
I've been trying to recreate what I was doing before and I have been able to do it.  However, do you have the ability the modify the id of the "linkbutton" to be equivalent to the value you want to query in your database?  If you can, then what I did will definitely work.  If not, I'm afraid it might not be able to.  So can you assign the value of the id equal to the vendor information you want to query?
0
 

Author Comment

by:NickMalloy
ID: 13870703
sure. I can format the link using XSL to look however I want
0
 
LVL 8

Accepted Solution

by:
thrill_house earned 500 total points
ID: 13870934
Ok great.  Here is what I did.  I basically recreated exactly what asp.net does, by performing a doPostBack on the hyperlink


This is what my "test" form looks like

<form id="Form1" method="post" runat="server">
                  <input type="hidden" name="__EVENTTARGET" value="" />
                  <input type="hidden" name="__EVENTARGUMENT" value="" />
                  <script language="javascript" type="text/javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
  var theform;
  if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
    theform = document.Form1;
  }
  else {
    theform = document.forms["Form1"];
  }
  theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
  theform.__EVENTARGUMENT.value = eventArgument;
  theform.submit();
}
// -->
</script>
                  <a id="test" href="javascript:__doPostBack('test','')">Testing</a>
            </form>


You'll need that script and you will need to declare and set the _EVENTTARGET and _EVENTARGUMENT like I did (just copy it).

Then notice that in a href I did the call to the javascript.  This will cause a postback.  (You need the first parameter to be equal to the id)

On the page load you will have to see if __EVENTTARGET has a value by doing this:
Request.Form("__EVENTTARGET") <> ""


If it has a value that means that your hyperlink has caused a postback, and Request.Form("__EVENTTARGET") should have the value you want.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 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