|
I want validation for text box in a text box enter only whole numbers(no decimal). The keypress event is not available in ASP.Net.
How to get key press event?
Can it be done using regular expression validator?
Cheers
Berba
modified 28-Nov-11 7:23am.
|
|
|
|
|
ASP.NET is serverside. You will have to use javascript.
JQuery validation is a good plave to start
---------------
stian.net
|
|
|
|
|
yes you can use regular expression ie) [^0-9].
|
|
|
|
|
You can use a MaskedEdit textbox and set the mask to only accept numbers. No validation or event handling needed.
No comment
|
|
|
|
|
Use a javascript/jquery function to achieve this:
1. HTML Mockup
<input id="txtNumbersOnly" runat="server" onkeypress="Validate($(this));" />
Above, "onkeypress" is the client-side keypress event. For more accuracy, you could replace "onkeypress" with "onkeyup" which only fires when you let go of a "key" (on your keyboard).
2. Javascript/jQuery
function Validate( sender )
{
if( parseInt( sender.val() ) )
{
}
else
{
alert( 'Sorry, only whole numbers are allowed in this input field. Please try again.' );
}
}
|
|
|
|
|
I have a Web Form and wish to scroll to a specific row when the DataGridView is populated. This is especially relevant when the user has clicked the Edit button having scrolled down the screen and I want to present the row to be edited, not the first row of the grid.
I have seen many solutions on how to achieve this in a Windows form; principally by using the DataGridView.FirstDisplayedScrollingIndex property.
But I am working in a ASP.net Web form environment where this property is not (obviously) available.
Can someone point me in the right direction of the equivalent C# program code for achieving this in a Web Form. Maybe there's some other "System." assembly I have to include upfront that will enable the constructs that I need.
|
|
|
|
|
You can du this by adding an anchor on each row and then link to mygrid.aspx#anchorname to scroll to that row.
Add an <a name="<%#Eval("id")%>"></a> and link to mygrid.aspx#123
---------------
stian.net
|
|
|
|
|
What does the following parameter syntax mean?
@Html.DisplayFor(modelItem => item.Title)
Particularly, the => symbol?
The difficult we do right away...
...the impossible takes slightly longer.
modified 27-Nov-11 16:07pm.
|
|
|
|
|
OK, I see that's the Lambda syntax. I have to learn about that now.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I am working on a C# web form 2010 new application and I have a question about how to setup a validation control. In a dropdown list control I would only like to list the dates values that are in a certain date column in the table called 'master'. I would like a validation control to make certain the only dates allowed are in the 'receive date' column of the 'master' table. How would you set this up?
|
|
|
|
|
If the only allowable dates are in one column in a database table then populate the dropdown with those values. No validation necessary since the only values are those that are valid. I'm I missing something?
No comment
|
|
|
|
|
The problem is the Month and Year values have to be in separate dropdown lists accoding to the user. Also the month and year values do not end in December. All values can start in any month/year combination.
modified 27-Nov-11 21:33pm.
|
|
|
|
|
I am using MVC 2 on VS2010 and IIS 7. I created a portable area with some images embedded into it. I tried to create routing rule two ways at the time of portable area registeration. Following are the two ways I tried.
Method 1
context.MapRoute("ResourceRoute", "login/resource/{resourceName}",
new { controller = "EmbeddedResource", action = "Index" },
new string[] { "MvcContrib.PortableAreas" });
context.MapRoute(
"login",
"login/{controller}/{action}",
new { controller = "login", action = "index" });
RegisterAreaEmbeddedResources();
In this case I tried to access the image using Url.Resource()
Method 2
context.MapRoute(
"login",
"login/{controller}/{action}",
new { controller = "login", action = "index" });
RegisterDefaultRoutes(context);
RegisterAreaEmbeddedResources();
In this case I tried to access the image using Url.Content()
Following are scenarios where things are working fine.
1. When I run the application on my local development server (Ctrl + F5).
2. When run application after publishing it on my localhost.
3. When I run the application on different development server (Ctrl + F5), say on my friend's box.
But it does not render image (right now I have only images as static resource. No CSS or JS) if I publish on someone else's system, say localhost on my friend's box. Everything else is working fine except for the image rendering.
I have tried all possible means to get it rendered in the situation it is failing but all in vain. I need some help here. Anyone please?
Thank you in advance!
|
|
|
|
|
Have you taken a look at the html in the browser source, to verify it's correct when it doesn't work?
|
|
|
|
|
Yes I have checked. They are all good at all time.
For Method 1 I used
Url.Resource("Images.aw1.png")
Here the image was located under Images folder which was under the root of Portable area project. URL of the image is rendered as "http://locahost/mysite/login/resource/Images.aw1.png"
For Method 2 I used
Url.Content("~/LoginPortableArea/Images/aw1.png")
Here LoginPortableArea is name of the area and images are located in the folder Content/Images which was under the root of portable area project. URL of the image is rendered as "http://localhost/mysite/LoginPortableArea/Images/aw1.png".
So we see in both the cases url is correctly generated and the image also gets rendered correctly on localhost of my box but not elsewhere.
|
|
|
|
|
Packer L wrote: "http://locahost/mysite/login/resource/Images.aw1.png"
Looks like the image is hard coded to localhost, using a full url. With a partial url, you don't have to worry about the server name, the browser will take care of that.
If an image is embedded, then that image in the server control project must be marked as embedded in the property panel, so it gets compiled into the DLL. When the image is called for duty, the image is extracted from a webresource.axd, and the url looks sort of like ~/webresource.axd/sfdf.png
I'm pretty sure you can't embed an image in a web project.
|
|
|
|
|
No the image is not hard coded with localhost. For the sake of clarity I mentioned it like that. It actually is rendered as "/mysite/login/resource/Images.aw1.png"
And as a matter of fact images are being embedded in web app assembly. This can be done by setting image property "Build Action" to "Embedded Resource". I can guarantee that embeding of resource is working fine or else image would not have got rendered on my local too. Moreover I also checked the DLL through a reflector and saw that images were indeed embedded there.
|
|
|
|
|
Sounds like you got it figured out now. Good Job!
|
|
|
|
|
No but it is still not working. Everything looks good but it is still not working. Hints please!
|
|
|
|
|
With all due respect,
I offered sound and sane suggestions in diagnosing your issue, but you turned them all down. If you look at the browser source, and take the image url and paste in your browser url, you should be able to pull up the image, that simple.
But I have worked with folks in my lifetime ( 48 years ), in which each time they claim that they have done that, and rule out any suggestion offered, which is YOU!
You can't be helped, until you get humbled or something, or perhaps open up your mind to critical thinking.
Sorry, I'm done.
jkirkerx
|
|
|
|
|
Well due respect to you too,
I had already tried all your sane diagnosing methods before I even thought of coming online for help. I just wanted to say that I have tried them already and in-fact I tried them again on your suggestion but it looks like you took it different way and that is not my fault.
Just because you have 48 years of experience doesn't mean your suggestion has to be spot on. And so far opening of mind for critical thinking is concerned, point one, I know what I am and don't need certificate from anyone and point two, do you really think you offered suggestion that required critical thinking?
And so far being humble is concerned, I always am but not now. This is the worst online reply that I ever gave to anyone and sorry to say but you forced me to do that.
I am not sorry at all for replying to you like this.
Packer
|
|
|
|
|
Please accept my apology.
I get frustrated sometimes, and probably should of just been more direct. On the other forum, I just ignore the questions now, and don't get involved anymore.
Diagnostics:
Sometimes you have to work backwards, and look at the final results in the browser output. If the results don't work, you have to pick it apart. So you start at the image tag, inspect the url. test the url in the browser bar.
There's a ton of information in the browser source, it just takes some learning to read the info and understand it. If you code in CSharp, then the principals are the same.
Now you work forward on the source, to make adjustments to what is sent back to the browser.
The most common mistakes I see is in the use of Client Script Manager, and not registering the CS in OnInit. The 2nd mistake is not using CS WebResuorceUrl as the url in the image tag. The image url is a webresource.
Sample Code in vb. This is for you to just get an idea of the stucture and use of of the client script manager, and the webresource url.
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
MyBase.OnInit(e)
Controls.Clear()
Dim cs As ClientScriptManager = Me.Page.ClientScript
Dim rsType As Type = Me.GetType()
Select Case [Localization]
Case 0
rm = New ResourceManager("Admin_PP_Standard.labels_en", Assembly.GetExecutingAssembly())
ci = New CultureInfo("en-US")
Case 1
rm = New ResourceManager("Admin_PP_Standard.labels_fr", Assembly.GetExecutingAssembly())
ci = New CultureInfo("fr-CA")
Case 2
rm = New ResourceManager("Admin_PP_Standard.labels_es", Assembly.GetExecutingAssembly())
ci = New CultureInfo("es-MX")
End Select
Dim Comment As LiteralControl
Comment = New LiteralControl
Comment.Text = "<!-- SignUp V1.1 for ASP.NET 4.0 -->" & vbCrLf
Controls.Add(Comment)
Dim img_Name As String = Nothing
Dim img_Email As String = Nothing
Dim img_ProgressIndicator As String = Nothing
Dim img_Connect As String = Nothing
Dim img_BG_ModalProgress As String = Nothing
Select Case [Page_ColorTheme]
Case 0
img_Name = cs.GetWebResourceUrl(rsType, "Footer_SignUp.ico-form_person_light.png")
img_Email = cs.GetWebResourceUrl(rsType, "Footer_SignUp.ico-form_envelope.png")
img_ProgressIndicator = cs.GetWebResourceUrl(rsType, "Footer_SignUp.modalProgress32.gif")
img_Connect = cs.GetWebResourceUrl(rsType, "Footer_SignUp.btn-send_it_on_connect.png")
img_BG_ModalProgress = cs.GetWebResourceUrl(rsType, "Footer_SignUp.modal_ProgressIndicator.png")
Case 1
img_Name = cs.GetWebResourceUrl(rsType, "Footer_SignUp.ico-form_person.png")
img_Email = cs.GetWebResourceUrl(rsType, "Footer_SignUp.ico-form_envelope.png")
img_ProgressIndicator = cs.GetWebResourceUrl(rsType, "Footer_SignUp.modalProgress32.gif")
img_Connect = cs.GetWebResourceUrl(rsType, "Footer_SignUp.btn-send_it_on_connect.png")
img_BG_ModalProgress = cs.GetWebResourceUrl(rsType, "SmartWeb.ContactUs.modal_ProgressIndicator.png")
Case Else
img_Name = cs.GetWebResourceUrl(rsType, "Footer_SignUp.ico-form_person.png")
img_Email = cs.GetWebResourceUrl(rsType, "Footer_SignUp.ico-form_envelope.png")
img_ProgressIndicator = cs.GetWebResourceUrl(rsType, "Footer_SignUp.modalProgress32.gif")
img_Connect = cs.GetWebResourceUrl(rsType, "Footer_SignUp.btn-send_it_on_connect.png")
img_BG_ModalProgress = cs.GetWebResourceUrl(rsType, "SmartWeb.ContactUs.modal_ProgressIndicator.png")
End Select
ib_Connect = New ImageButton
With ib_Connect
.ID = [ID] & "_ib_Connect"
.ImageAlign = ImageAlign.Left
.ImageUrl = img_Connect
End With
td_Connect.Controls.Add(ib_Connect)
The 3rd mistake I see is not registering the embedded material in the assemblyInfo.
<Assembly: WebResource("Footer_SignUp.btn-send_it_on_connect.png", "image/png")>
<Assembly: WebResource("Footer_SignUp.ico-form_envelope.png", "image/png")>
<Assembly: WebResource("Footer_SignUp.ico-form_person.png", "image/png")>
The 4th mistake is not using the proper root namespace.
root namespace.imagefilename.extension
Right click your project in ssolution explorer, , select the application tab, at the top, you'll see your Assembly Name and Root Namespace.
The 5th mistake is not declaring the right mimetype in the AssemblyInfo. "image/png"
Now you have the page lifecycle. These are the basic building blocks.
OnPreRender - Really special purpose - You don't need it
OnInit - Create the server controls, and builds the page in server memory as htmltextwriter
OnLoad - Populate the server controls with data. - Override for Page.Load
Render - Write out the htmltextwriter, and send to either design mode or browser window.
////////////////////////////////////////////////////////////////////////////////////////
CreateChildControls - Called automatically, but you can override it
OnLoad - called automatically - but you can override it.
Solution:
You can private message me your browser source, so I can see the end results. Or point me to a url where I can see the html output.
Or you can send me a sample of your code module, so I can see what you have going.
|
|
|
|
|
Hi,
How to create AJAX enabled website in VS 2010
I had placed script manager and update panel.But on each menu su-item click the full page ie header,content placeholder and footer are refreshing.Need help....
S.Guhananth
|
|
|
|
|
Just placing a script manager, or any other control, on the page doesn't make it Ajax. You need to actually write some code, javascript and server-side. I would suggest you do some research and understand what Ajax is and means first.
No comment
|
|
|
|
|
The update panel is part of the System.Web library, in which it allows you do async post-backs to the server, so only the content or HTML markup inside the update panel is makes a round trip to the server, instead of the whole page.
Microsoft AJAX is part of the AJAX Control Toolkit. You have to download the project, and compile it. Then you make a reference to the AjaxControlToolkit.dll inyour project, so you can access the tools.
Search for the AJAX Control Toolkit and you'll get a blue colored website, in which you can test the tools, and download the source. There is a video you can watch as well.
|
|
|
|