Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

asp:button question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hal - 29 May 2008 16:41 GMT
Is it possible when an asp:button is clicked I can have the button use
javascript client side code and fire the click event for the button
for server side code?  Code below is an example of what i'm trying to
do:

   <script type="text/javascript">

function SetImage()
         {
           alert("Testing");
         }

   </script>

<asp:ImageButton ID="btnSubmit" runat="server" ImageUrl="~/Images/
signin_btn.gif" Width="103" Height="33" OnClick="btnSubmit_Click" />

       protected void btnSubmit_Click(object sender,
ImageClickEventArgs e)
       {
           //Doing Stuff
       }

I've tried playing around with this code in Page_Load and can't get it
to work:

btnSubmit.Attributes.Add("onclick", "SubmitLoginForm()");

Is this possible to do, and if so what am i missing?

Thanks
Mark Rae [MVP] - 29 May 2008 16:54 GMT
> Is this possible to do, and if so what am i missing?

<asp:ImageButton ID="btnSubmit" runat="server"
ImageUrl="~/Images/signin_btn.gif" Width="103" Height="33"
OnClick="btnSubmit_Click" OnClientClick="SetImage();" />

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

hal - 29 May 2008 17:27 GMT
Thanks that works fine when the page is posting back to itself.  In
javascript code i have the page re-directing somewhere else, and with
your changes it still does hit the server side code.  I also tried
testing this without the javascript code doing the re-direct and
putting a postbackURL on the button and that also did not hit the
server side code.

Any other suggestions?

Thanks
Mark Rae [MVP] - 29 May 2008 17:33 GMT
> In
> javascript code i have the page re-directing somewhere else, and with
[quoted text clipped - 4 lines]
>
> Any other suggestions?

Slightly puzzled... Do you want this control to have any server-side
functionality or not...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.