Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
89
rated 0 times [  92] [ 3]  / answers: 1 / hits: 72826  / 11 Years ago, tue, december 10, 2013, 12:00:00

I have a button declared like this:



<asp:Button id=Send runat=server EnableViewState=False 
ToolTip=Email me this report CssClass=Button Text=Email me this report>
</asp:Button>


But if I do Inspect Element in browser, it shows like this:



<input type=submit class=Button title=Email me this report 
id=ctl03_Toolbar_Send onclick=javascript:WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions(ctl03$Toolbar$Send,, true, , ;, false, false))
value=Email me this report name=ctl03$Toolbar$Send>


I wonder where the onclick event comes from? What does it do?



Thanks for your help in advance.


More From » asp.net

 Answers
3

If you set the PostBackUrl property for the Button server control, then it means it is cross page posting and then asp.net framework instead of normal __DoPostBack() adds WebForm_DoPostBackWithOptions. Check if you have PostBackUrl Property set for this button.



<asp:Button id=Send runat=server EnableViewState=False PostBackUrl=~/Page2.aspx
ToolTip=Email me this report CssClass=Button Text=Email me this report>
</asp:Button>


If in your case you have not set the PostBackUrl, then ASP.NET framework also does not add this by default for Button Control, so this means there has to be another control setting the OnClick attribute value probably using following sever side code -



    PostBackOptions myPostBackOptions = new PostBackOptions(this);
myPostBackOptions.ActionUrl = Page2.aspx;
myPostBackOptions.AutoPostBack = false;
myPostBackOptions.RequiresJavaScriptProtocol = true;
myPostBackOptions.PerformValidation = true;

// Add the client-side script to the HyperLink1 control.
Button1.OnClientClick = Page.ClientScript.GetPostBackEventReference(myPostBackOptions);

[#73812] Monday, December 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
turnerf

Total Points: 620
Total Questions: 101
Total Answers: 109

Location: French Polynesia
Member since Tue, Jul 7, 2020
4 Years ago
turnerf questions
;