Solved

VB script function not firing from asp:button click

Posted on 2013-01-28
7
874 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now