Solved

VB script function not firing from asp:button click

Posted on 2013-01-28
7
932 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 25 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 475 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 475 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where does legacy ASP.NET initialize language? 2 64
VB script help 23 36
Get the Y value of a line at X in a chart in VBA 28 32
Need help for captcha 2 23
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…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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