Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB script function not firing from asp:button click

Posted on 2013-01-28
7
Medium Priority
?
1,004 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Loops Section Overview
Suggested Courses

610 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