?
Solved

VB script function not firing from asp:button click

Posted on 2013-01-28
7
Medium Priority
?
976 Views
Last Modified: 2013-01-30
Hi,
I have a vbscript function on the page to open the calendar.I am trying to fire this from button click event.
I am getting this error 'getdate' is not a member of 'ASP.default_aspx'.
Function getdate
            frm1.txtdate.value = window.showModalDialog("calendar.aspx","","dialogHeight: 200px;dialogWidth: 400px;status:no;" )
     
      End Function


     <asp:Button id="btnDate" runat="server" alt="Calendar" onclick="getdate()" align="top" border="0" />

Before it was image  and it's firing the getdate function.Now I changed it from iamge button to regular button and it is not firing the getdate function.

Any suggestion please.
0
Comment
Question by:KavyaVS
[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
  • 3
  • 3
7 Comments
 
LVL 16

Assisted Solution

by:Kamal Khaleefa
Kamal Khaleefa earned 100 total points
ID: 38829862
hi
add onclick event on your code behind like this

  Private Sub btnDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDate.Click


'here call ur function
getdate()

 End Sub
0
 
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 1900 total points
ID: 38830178
Where is "Function getdate" defined/written out? Looking at the call inside it needs to be client side. That would mean you would have to use OnClientClick instead of OnClick:
<asp:Button id="btnDate" runat="server" alt="Calendar" OnClientClick="getdate()" align="top" border="0" />

Open in new window

Some more changes might be necessary to prevent the button from posting back.

* Alternatively you could use a simple HTML button instead of ASP button if you just want client side functionality:
<input id="ButtonChooseDate" type="button" value="choose date" onclick="getdate()" />

Open in new window

0
 

Author Comment

by:KavyaVS
ID: 38835325
Hi robert_Schutt
I tried the OnClienClick="getdate();" but it is not working.The calenadar is not showing up.there is no error also.

The getdate function defined in the head section of aspx page.
To maintain consistency I have to use the asp button controls.I can't use HTML button controls Because few more asp buttons are there on the same row.

Any suggestions please.

Thanks.
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!

 
LVL 35

Accepted Solution

by:
Robert Schutt earned 1900 total points
ID: 38835747
Please post the relevant part of your html, or see if you can get what you need from this working code where I converted the getdate function to javascript:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> EE Q_28011236 </title>
    <script type="text/javascript">
        function getdate() {
            document.forms['frm1'].txtdate.value = window.showModalDialog("calendar.aspx","","dialogHeight: 200px;dialogWidth: 400px;status:no;" );
            return false;
        }
    </script>
</head>
<body>
    <form id="frm1" runat="server" clientidmode="Static">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" onclientclick="return getdate()" />
        <input name="txtdate" />
    </div>
    </form>
</body>
</html>

Open in new window

The return false is to stop the form from being posted back, which I assumed would be needed to just show the date in the textbox and be able to continue filling in the form.
0
 

Author Comment

by:KavyaVS
ID: 38837184
Hi robert_Schutt

Thank you very much.It is working now.Even If I commented the return false; in the java script function it is working fine.

Is it vbscript preventing it from working?

I will post another question regarding how to pass parameters to java script function from OnClient Click(from the Link button in DataGrid)
If you have any suggestion please let me know.

Thanks
0
 

Author Closing Comment

by:KavyaVS
ID: 38837198
Greatly Appreciated.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38837808
Is it vbscript preventing it from working?
In IE it should be possible to make it work but without seeing the relevant part of your html I can't tell what was wrong with it. I tried to get it to work but couldn't so I posted an alternative.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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
Course of the Month11 days, 13 hours left to enroll

752 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