c# - Problem on how to update the DOM but do a check on the data with the code-behind -
this asp.net web forms .net 2.0 -
i have situation not sure how fulfill requirements. need update img source on page if selections made drop down on same page.
basically, drop downs 'options' item. if selection made (i.e. color: red) update img product (productid_red.jpeg) if 1 exists.
the problem don't want post backs , refresh page every time selection made - if check see if image exists before swap out img src product , file doesn't exist refreshed entire page nothing.
question:
so have thrown javascript formulates string of image file name based on options selected. question is, options have following:
submit constructed image name (i.e. productid_red_large.jpg) verify file exists either in c# or if possible in javascript. have check different possible file types (i.e. .png, .jpg...etc.).
not post , refresh entire page
any suggestions?
submit constructed image name (i.e. productid_red_large.jpg) verify file exists either in c# or if possible in javascript. have check different possible file types (i.e. .png, .jpg...etc.).
not post , refresh entire page
if wish not post page want @ $.ajax() or $.post() (which short hand $.ajax()
default options)
to handle request use generic http handler.
a simple outline work following:
jquery example post:
$("somebutton").click(function () { //get image name var imagetocheck = $("#imgfilename").val(); //construct data send handler var datatosend = { filename: imagetocheck }; $.post("/somepath/validateimage.ashx", datatosend, function (data) { if (data === "valid") { //do } else { //handle error } }, "html"); })
then on asp.net side create http handler validate request.
public class handler1 : ihttphandler { public void processrequest(httpcontext context) { var filename = context.request["filename"]; var fullpath = path.combine("somelocalpath", filename); //do validate file if (file.exists(fullpath)) { context.response.write("valid"); } else { context.response.write("invalid"); } } public bool isreusable { { return false; } } }
hope helps, if missed mark @ on let me know , can revise.
Comments
Post a Comment