How To Replace A Function Name Using JavaScript And Have It Be Recognized As A Function

Aug 25, 2010

I am trying to replace the JavaScript onclick event handler in ASP.NET that is added to a button control when using validation controls. This is what is output into the HTML from ASP.NET in this scenario:

<input type="image" name="ibSubmit1" id="ibSubmit1" src="button-green-submit.gif" onclick="showProgress1();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ibSubmit1", "", true, "Group1", "", false, false))" style="border-width:0px;" />

I have looked pretty estensively, and unfortunately there doesn't seem to be a way to modify the function server side before it is injected into the page.

Since I am developing a control and desire it to be non-invasive and self contained, and I am interested in obtaining the validationGroup parameter of the WebForm_PostBackOptions object, it seems that the easiest solution would be to use JavaScript to replace the WebForm_DoPostBackWithOptions function name with my custom wrapper function and leave all of the rest of the parameter information intact - then I can extract the information I am interested in, call my custom functions, and then forward the call on to WebForm_DoPostBackWithOptions.

NOTE: I am using jQuery to build my custom function, so if there is an easier way to do this with jQuery it is an option I will consider.

Here is the code I tried to replace the onclick event handler (not working):

$('[onclick*=WebForm_DoPostBackWithOptions]').each(function() {
var txt = this.onclick;
txt = txt + '';
txt = txt.replace('WebForm_DoPostBackWithOptions','ml_DoPostBackWithOptions');
this.onclick = eval(txt);
});

Using alert(), I verified that the text is being changed correctly, however whether or not I use the eval() function, the onclick handler doesn't seem to recognize it as JavaScript.

I thought of using a regular expression to get the validationGroup value, but this seems like it will be far more elegant and flexible if I can get it working...

Note: If there is a way for my control to interrogate the page it is on to find all of the buttons that will post back (regardless of what type of buttons they are) so I can retrieve the property server-side, this is also something I will consider.

View 3 Replies


Similar Messages:

Call Javascript Function And Server Side Function From Linkbutton

Jan 27, 2010

<asp:LinkButton CssClass="button" ID="btnApply" runat="server" OnClick="btnApply_Click()" OnClientClick="Apply1('btnApply')" >
hi ihave this functin in .vb file
Protected Sub btnApply_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApply.Click
end sub

and javascript function also in aspx

function ApplySummerization(id)
{
alert("hai");
}

View 4 Replies

Web Forms :: Getting Error Calling Javascript Function From Another Javascript Function

Jan 3, 2011

Getting error calling Javsscript function from another Javascript function

[Code]....

View 4 Replies

Using RegEx Replace Function In C# ASP?

Feb 18, 2010

How do I solve the problem below? I'm creating a simple content management system, where there is a HTML template with specific markup that denotes where content should be:

<html><head></head><body><!-- #Editable "Body1" --><p>etc etc</p><!-- #Editable "Extra" --></body></html>

Separate from this, there is content in a database field that looks a little like this:

<!-- #BeginEditable "Body1" -->This is Test Text<!-- #EndEditable --><!-- #BeginEditable "Extra" -->This is more test text<!-- #EndEditable -->

As you can guess I need to merge the two, that is, replacing

<!-- #Editable "Body1" -->

with: This is Test Text. I've begun the code here. But I'm having problems using the Regex Replace function that should be located at the very bottom of that For/Each.

//Html Template
string html = "<html><head></head><body><!-- #Editable "Body1" --><p>etc etc</p><!-- #Editable "Extra" --></body></html>";
//Regions that need to be put in the Html Template
string regions = "<!-- #BeginEditable "Body1" -->This is Test Text<!-- #EndEditable --><!-- #BeginEditable "Extra" -->This is more test #EndEditable -->";
//Create a Regex to only extract what's between the 'Body' tag
Regex oRegex = new Regex("<body.*?>(.*?)</body>", RegexOptions.Multiline);
//Get only the 'Body' of the html template
string body = oRegex.Match(html).Groups[1].Value.ToString();
// Regex to find sections inside the 'Body' that need replacing with what's in the string 'regions'
Regex oRegex1 = new Regex("<!-- #Editable "(.*?)"[^>]*>",RegexOptions.Multiline);
MatchCollection matches = oRegex1.Matches(body);
// Locate section titles i.e. Body1, Extra
foreach (Match match in matches)
{
string title = oRegex1.Match(match.ToString()).Groups[1].ToString();
Regex oRegex2 = new Regex("<!-- #BeginEditable "" + title + ""[^>]*>(.*?)<!-- #EndEditable [^>]*>", RegexOptions.Multiline);
//
//
// Replace the 'Body' sections with whats in the 'regions' string cross referencing the titles i.e. Body1, Extra
//
//
//
}

View 5 Replies

Databases :: Use MySQL Replace Function In C#?

Aug 5, 2010

I am trying to use the MySQL replace function in C# but the resulting data ignores the columns inside the REPLACE function - i guess its because C# has its own Replace function

get the required column either through Mysql escape sequence or in the C# syntax

MySqlConnection mySqlConnection1 = new MySqlConnection("server=localhost; database=faohr; pooling=false; allow zero datetime=yes;");

View 2 Replies

Forms Data Controls :: Replace Function In A Gridview?

Jul 26, 2010

I am trying to replace carriage returns from a column in a database (MS access) with the br tag.

This could be easily done in classic ASP with <% = replace(recordsetField , Chr(13),"<br>") %>

Not sure how I would do it with .net (c#)

View 6 Replies

Web Forms :: Finding Function To Stop The Import Function If Tags Are Not In Desired Order

May 11, 2010

I have this import function which can be changed by the client in his desired way.Now I want to code such that if the client tries to import his own data on the page and doesnot give the tags in the order mentioned below his import function should be stopped.

It shouldn't make any changes unless the tags are in the right format because the problem now is if the tags are not in the right format when client changes then its importing over the existing files and directing to an error page which I dont want it should simply stop the import function if they are nt in the order.the code for this function is below

[code]....

View 7 Replies

MVC :: Implement In This Function Public Function FetchData (ByVal DropdownValue As String)?

Jan 5, 2010

i followed this link [URL] and i get selected value from dropdownlist using jquery

i created 3 partial views .

i need depend's on dropdownvalue redirect to partial page , so how can i implement in jquery with conditions?? or how can i implement in this function Public Function FetchData(ByVal dropdownValue As String) As ActionResult??

View 1 Replies

MVC :: Razor Function And Lambda Functions / Write A Function To Reuse Some Functionality?

Mar 8, 2011

I would like to write a function to reuse some functionality that I repeat over and over...

For example:

[code]....

What's changing, in every field, is only the lambda function to get the current field to edit (Name, City, Address, etc...).

What is the best method? Or better: is there ANY method to extract a generic function?

View 18 Replies

DataSource Controls :: How To Use Cursor In Recursive Sql Function (scalar-value Function)

Apr 25, 2010

how can i use cursor in this function ?

ALTER FUNCTION [dbo].[GetCatIDChilds]

(

@CatID [code].....

View 1 Replies

Call Codebehind If Javascript Doesn't Exist In Browser - Else Javascript Function

Sep 29, 2010

In asp.net page, How can i call the javascript methods for form processing-submitting if the user browser supports javascript and use code behind events if the browser does not support javascript.I have the javascript code to send the form data to an ajax server page using jquery. Don't know how to invoke the needed one based on the browsers javascript availability

View 1 Replies

Web Forms :: How To Create C# Search Function And Add Friend Function

Jan 1, 2010

I need to create something which is like an Add friend function in my website which works like this:

1) User types in name of the person he wants to search in the search field and clicks enter

2) on the same page, the search result will come out with an "add friend" button beside every name

3) when the user clicks the "add friend" button, he will be brought to another page (or pop up with a message box?) with a text message field to send to the friend, and a submit button to submit the friend request.

4) over at the Friend's page, he will be able to view the add friend request and decide whether to accept or deny the friend request.

View 1 Replies

C# - How To Override The Same Function On Multiple Pages (Render Function)

Jan 26, 2011

Take the following scenario. I have multiple ASPX pages. Login, Logout, Main, Messages, etc... They all inherit from System.Web.UI.Page of course. For all the pages, I want to override the Render method from the Page class. I could easily copy and paste the same code into each page like so:

protected override void Render(HtmlTextWriter writer)
{
//Code Logic Here
}

But if I had many pages, lets say 20, maintaining the code in each page could get very time consuming and error prone.That made me think a bit and I thought okay lets try this...override the function in each page but call a static function. That way changing the static function would result in a change for every page.Which works fine... But its not really nice and clean, having to override like that on every single page.

View 3 Replies

Call On Onclient Event But Keeps Saying Function 'function Not Defined'

Dec 3, 2010

i got a javascript function that i want to call on <aspImabutton onclient event but it keep saying function not defined.

[Code]....

View 2 Replies

JavaScript - User Control JavaScript Function Doesn't Run

Sep 22, 2010

I have the function put here like below:

$(document).ready(function () {
UserControlNameInit();
});

The script are put in the following and the block is in the .ascx page.

<script type="text/javascript">
</script>

However, the function UserControlNameInit() does not run when the page loads. It is showing in the page source. I can still call this function through FireBug console by manually typing the name of the function.

I did the same way with other user controls, and it works. Just 1-3 user controls are not working...

View 1 Replies

Can Integrate A C Function Or Say Can Use Java Or Say Some Other Language Function?

Sep 1, 2010

can we integrate a c function or say can we use java orsay someother language function by using file handeling

View 2 Replies

Does A Return Statement In Function Stop The Function

Jun 8, 2010

Given the function

[code]....

When 'return false' is fired, I'm assuming that the function is stopped at that point and there's no need for exit fors and things like that?

View 1 Replies

How To Override A Function And Call A Function With The Same Name From The Grandparent

Sep 6, 2010

I am attempting to inherit an ASP.NET RegularExpressionValidator and add some functionality to it. I inherited the control and added my custom properties. However, I would also like the client-side functionality to call a different JavaScript functionIn order to do that, I will need to supress what is happening in the AddAttributesToRender method because the name of the function is hard-coded there.

Protected Overrides Sub AddAttributesToRender(ByVal writer As HtmlTextWriter)
MyBase.AddAttributesToRender(writer)
If MyBase.RenderUplevel Then
Dim clientID As String = Me.ClientID
[code]...

View 1 Replies

C# - Javascript Function Don't Run At Once?

Feb 13, 2011

I've some function javascript to check loaded file with FileUpload Control

<script language="javascript" type="text/javascript">
function CheckFileBeforeUpdate()
{
var filePath = document.getElementById('<%= this.upFile.ClientID %>').value;
var validExtension = 'xml';
var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
if (ext == validExtension) return true;
alert('The file extension ' + ext.toUpperCase() + ' is not allowed!');
return false;
}
</script>

and it's called with Button: OnClientClick="return CheckFileBeforeUpdate();

<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In"
onclick="LoginButton_Click" OnClientClick="return CheckFileBeforeUpdate();" />

So there's unusual situation: I choose appropiate file, click Login...and it goes on to next functions despite inadequate extension.

Otherwise if I e.g. click FileUpload, but select no file.
Next time I choose some file (even with bad extension) and then function run (shows alert).

Why there's sth like blockade? What can I do to change CheckFileBeforeUpdate() runs everytime?

EDIT
if I select no file there's show alert("Select file to log in"); of course. And then is lock release

[Code]....

View 2 Replies

Calling Javascript Function From VB.Net?

Nov 15, 2010

Is is possible to call a Javascript function whether it's embedded in the HTML markup file or a .js file from a VB.Net procedure/function?

View 3 Replies

How To Create A Javascript Function

Mar 17, 2010

I'm working on an MVC application and I ran into a little snag.

I've got a form with the usual textboxes and dropdowns. I decided to use jquery ajax (GET) to load the dropdowns on load (State Names & Salutations).

No matter what I try, for example:

Code:
<AcceptVerbs(HttpVerbs.Get)> _
Public Function ReturnSalutationDropdown() As ActionResult
Dim dropdown As New DropDownList With {.TabIndex = 1, .DataTextField = "Value", _
.DataValueField = "Key", .ID = "ddl_coSalutation"}
dropdown.DataTextField = "Value"
dropdown.DataValueField = "key"
dropdown.DataSource = AppEnumerations.BindToEnum(GetType(AppEnumerations.Salutation))
dropdown.DataBind()
Dim sb As New StringBuilder
Dim tw As New IO.StringWriter(sb)
Dim hw As New HtmlTextWriter(tw)
dropdown.RenderControl(hw)
Return Content(sb.ToString)
End Function

The ID of the dropdown ends up like: ctl00$MainContent$ddl_coSalutation

It doesn't matter if I use a stringbuilder and a loop to create a <select> with <option>'s, the ID always ends up like above.

Do I have to create a javascript function to create it instead?

View 5 Replies

Call C# Function From Javascript?

Jan 13, 2011

I have to call C# function from javascript?

View 5 Replies

Run One Javascript Function For Different Element?

Apr 3, 2011

how run one javascript function for diffrent element with one ASP.Net button click ?

View 1 Replies

C# - Javascript Function To Set Cookie Value?

Nov 8, 2010

I am new to programming and trying to write a javascript function to set a cookie value when a popup button is clicked.

In home.aspx

<input id="btnCanOK2" type="button" value="Close" class="popupButton" runat="server" onclick="return btnClose_Click" />

for this button, i have written a javascript function:

function btnClose_Click()
{
document.cookie = 'cookieName=closed; value=dontshowagain';
}

In merchant.login page

In the code behind of the other page, it has to check if the value of the cookie is set to "dontshowagain". If it is set to the value, the function should not show the popup again. My task is not to show the popup in different pages. If it is closed once, it has to stop showing again until the browser is closed.

if (Request.Cookies["closed"] == null)
{
ModalPopupextender2.Show();
}
else if(Request.Cookies["closed"].Tostring() == "dontshowagain")
{
ModalPopupextender2.Hide();
}

Where am i doing wrong?? Now Cookie value is always null :(

View 1 Replies

Javascript - How To Hit The Database On The Function

Dec 1, 2010

can I hit the database on my view?

I have function like this..

function ShowHIPAATab(url) {
if ($("#BxFlag").val() == "1") {
$("#bv-1").attr('src', url);
} else {
return false;
}
};

on this funcation I need to hit the database to get the BXFlag value.how to do that?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved