Solved

VB script function not firing from asp:button click

Posted on 2013-01-28
7
909 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
  • 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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