OnServerClick not working - asp.net

The event is simply not firing, what am I missing?
Code for the button:
<input type="button" class="button hide" id="savetext" style="float:right;" value="Hello" runat="server" OnServerClick="savetext_Click"/>
and the code that is generated (ie. when opened in a browser and the source is viewed) is this:
<input onclick="__doPostBack('ctl00$Main$savetext','')" name="ctl00$Main$savetext" type="button" id="savetext" style="float:right;" class="button hide" value="Save to text" />
I've got <pages clientIDMode="Static" /> in web.config but the name and generated onclick event are prefixed despite that.
Server side code:
Protected Sub savetext_Click(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
To be clear, my goal is to register a click on a button server-side, not just client-side. Thanks.

Maybe a javascript error stop it from running...
Well I say that because they only reason that is stop it from working, from the code I see was the javascript error.

Related

Open bootstrap modal from codebehind crashes tooltips

I build asp webform page (vb.net)
My tooltips crashes when I open modal from code behind using below code
Dim sb As New System.Text.StringBuilder()
sb.Append('&ltscript type='text/javascript'&gt')
sb.Append('$('#SetTime').modal('show');')
sb.Append('&lt/script&gt')
ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), 'SetTimeModalScript', sb.ToString(), False)
If I open the same modal form using button eg.
&ltbutton type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#SetTime"&gt Launch demo modal
&lt/buton&gt
everything works fine.
To initialize tooltips I use
$(document).ready(function () {
$('[data-tooltip="true"]').tooltip();
});
I try to find solution but I gave up after few hours.
I must use this code to open modal because I open it to display data for specific gridview row.
Edit
Here is part of code where I put data tooltip :
<asp:LinkButton runat="server" CssClass="btn btn-primary btn-xs" CommandArgument='<%#Eval("ID") %>' CommandName="SetTime" data-tooltip="true" title="Ustaw czas rozpoczęcia i zakończenia zlecenia" data-container="body"> <i class="fa fa-clock-o"></i> </asp:LinkButton>
I tried also with data-target="tooltip" instead data-tooltip="true"

Html control failing to hit codebehind method

I have a html button control which is targeting to execute code behind method but it is failing to do so I googled but couldn't fix so far..
<td>
<input type="button" runat="server" id="btnSend" class="btn" value="Send" onserverclick="btnSend_ServerClick" />
</td>
on view source I found the below..
<input onclick="__doPostBack('ctl00$ContentPlaceHolder1$btnSend','')" name="ctl00$ContentPlaceHolder1$btnSend" type="button" id="ctl00_ContentPlaceHolder1_btnSend" class="btn" value="Send" />
and the code behind method is as belwo..
protected void btnSend_ServerClick(object sender, EventArgs e)
{}
don't know what's preventing from hitting the method any suggestion/help on this would be of gr8 help.
In addition to above would also like to mention that the control is with in
<asp:UpdatePanel ID="ComposeUpdatePanel" runat="server"> and tried following this link
OnServerClick for button not working
without success..
I figured out the issue there was a textarea which has the content of the mail to which reply is being send and to display in format
<PRE>message content</PRE>
so the tag was causing the issue.
How ever removing the PRE tag causes the eventto fire but is there an alternate to retain format in TextArea so that the mail content would be displayed the way it was.

HTML textbox value always returns an empty string at asp.net button click event

I have a simple stopwatch application which updates HTML textbox values using a javascript.
<form name="clock">
<input type="text" size="12" name="stwa" value="00 : 00 : 00" style="texalign:center"/>
<input type="text" size="12" name="stwb" style="text-align:center" /><br />
<input type="button" name="theButton" onClick="stopwatch(this.value);" value="Start" />
<input type="button" value="Reset" onClick="resetIt();reset();" />
</form>
I also have an asp.net button control which should submit value in 'stwb' at the button click. Although stwb textbox gets updated with the javascript correctly, it always returns an empty string at button click.
<form id="form1" runat="server">
<asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click"/>
</form>
Button click event for the method.
protected void Button2_Click(object sender, EventArgs e)
{
String strValue = Page.Request.Form["stwb"].ToString();
Response.Write(strValue);
}
Appreciate any help in this regard.
You have two forms; HTML forms submit independently.
Thus, when your server form submits, the data for your "clock" form is not passed as part of the request.
The easiest solution is probably to place your clock inside the form with the runat=server attribute.

When a radio button is checked in one asp page,the result has to be displayed in another asp page..How to do that..pls explain?

Radio button in one aspx page ,
should display result in another aspx page
where was 2012 olympics held??
<form name="form1" action="resultpage.aspx" onclick="submit">
<input type="radio" name="VanPersie" id="a" value="paris" />paris<br />
<input type="radio" name="VanPersie" id="b" value="london" />london<br />
<input type="radio" name="VanPersie" id="c" value="rome" />rome<br />
<input type="submit" value="Submit"/>.
Above code displays my first home page and it has to be redirected to another aspx page....so when..london is checked by the user,it has to display the correct answer and i.e. London ..how to design the result page...
Presuming you have a button that fire a event in your page, you can set the PostbackUrl attribute to the page you want and where you can retrive the value
<asp:Button ID="btn" runat="server" Text="Send to other page" postbackurl="yourPage.aspx" />
Post ASP.NET Web Pages to a Different Page
1 You can use this code
var result = radioButtonList.SelectedValue;
Response.Redirect("AnotherPage?id=" + result);
In page you can get with
`QueryString["id"]`;
2 You can also use
yourButton.PostBackUrl = "AnotherPage.aspx?qid=" + radioButtonList.SelectedValue;
First set the method attribute to the form to POST
<form name="form1" action="resultpage.aspx" onclick="submit" method="POST">
Then, if you subit this form from an ASP page, in the resultpage.aspx you can get the radio value by:
//C#
protected void Page_Load(object sender, EventArgs e)
{
Request.Form["VanPersie"];
}
'VB
Protected Sub Page_Load(sender As Object, e As EventArgs)
Request.Form("VanPersie")
End Sub

JS callback on asp button

Um, I have this guy:
<div class="buttonRight"><asp:Button ID="btnOK" runat="server" Text="OK" Width="68px"/></div>
which renders out to
<div class="buttonRight">
<input type="submit" name="_$_$pc$pc$tabTO$_$uc0$popupSelectCompetition$btnOK" value="OK" id="____pc_pc_tabTO___uc0_popupSelectCompetition_btnOK" style="width:68px;" /></div>
I need to call some javascript on that button without altering its behavior otherwise. I tried putting an OnClick asp attribute but that seems to be for postbacks to call server code, not passing through a javascript hook to the rendered html.
I also don't understand how the input being type='submit' affects me.
Add your client-side code to the OnClientClick property :
<div class="buttonRight">
<asp:Button ID="btnOK" runat="server" Text="OK" Width="68px"
OnClientClick="alert('client side scripts here');"/>
</div>
OnClick property used for server side events.
Or add onclick attribute to your control like that at code behind :
btnOK.Attributes.Add("onclick", "alert('client side scripts here');");

Resources